Package org.springframework.validation

Examples of org.springframework.validation.ObjectError


      return new FieldError(
          fieldError.getObjectName(), fieldError.getField(), value,
          fieldError.isBindingFailure(), fieldError.getCodes(),
          fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage()));
    }
    return new ObjectError(
        source.getObjectName(), source.getCodes(), source.getArguments(),
        HtmlUtils.htmlEscape(source.getDefaultMessage()));
  }
View Full Code Here


  }

  private List escapeObjectErrors(List source) {
    List escaped = new ArrayList(source.size());
    for (Iterator it = source.iterator(); it.hasNext();) {
      ObjectError objectError = (ObjectError)it.next();
      escaped.add(escapeObjectError(objectError));
    }
    return escaped;
  }
View Full Code Here

   */
  private ActionMessages getActionMessages() {
    ActionMessages actionMessages = new ActionMessages();
    Iterator it = this.errors.getAllErrors().iterator();
    while (it.hasNext()) {
      ObjectError objectError = (ObjectError) it.next();
      String effectiveMessageKey = findEffectiveMessageKey(objectError);
      if (effectiveMessageKey == null && !defaultActionMessageAvailable) {
        // Need to specify default code despite it not being resolvable:
        // Struts 1.1 ActionMessage doesn't support default messages.
        effectiveMessageKey = objectError.getCode();
      }
      ActionMessage message = (effectiveMessageKey != null) ?
          new ActionMessage(effectiveMessageKey, resolveArguments(objectError.getArguments())) :
          new ActionMessage(objectError.getDefaultMessage(), false);
      if (objectError instanceof FieldError) {
        FieldError fieldError = (FieldError) objectError;
        actionMessages.add(fieldError.getField(), message);
      }
      else {
View Full Code Here

    MockRenderRequest request = new MockRenderRequest();
    MockRenderResponse response = new MockRenderResponse();
    ModelAndView mav = tc.handleRenderRequest(request, response);
    BindException errors = (BindException)mav.getModel().get(ERRORS_KEY);
    assertEquals("There should be 1 error", 1, errors.getErrorCount());
    ObjectError error = errors.getGlobalError();
    assertEquals(error.getCode(), errorCode);
    assertEquals(error.getDefaultMessage(), defaultMessage);
  }
View Full Code Here

    assertTrue("Correct number of errors", errors.getErrorCount() == 4);
    assertTrue("Correct object name", "tb".equals(errors.getObjectName()));

    assertTrue("Correct global errors flag", errors.hasGlobalErrors());
    assertTrue("Correct number of global errors", errors.getGlobalErrorCount() == 1);
    ObjectError globalError = errors.getGlobalError();
    assertTrue("Global error message escaped", "message: " '".equals(globalError.getDefaultMessage()));
    assertTrue("Global error code not escaped", "GENERAL_ERROR \" '".equals(globalError.getCode()));
    ObjectError globalErrorInList = (ObjectError) errors.getGlobalErrors().get(0);
    assertTrue("Same global error in list", globalError.getDefaultMessage().equals(globalErrorInList.getDefaultMessage()));
    ObjectError globalErrorInAllList = (ObjectError) errors.getAllErrors().get(3);
    assertTrue("Same global error in list", globalError.getDefaultMessage().equals(globalErrorInAllList.getDefaultMessage()));

    assertTrue("Correct field errors flag", errors.hasFieldErrors());
    assertTrue("Correct number of field errors", errors.getFieldErrorCount() == 3);
    assertTrue("Correct number of field errors in list", errors.getFieldErrors().size() == 3);
    FieldError fieldError = errors.getFieldError();
View Full Code Here

    assertTrue("Correct field", fe.getField().equals("name"));
    assertTrue("Correct validation code: expected '" +TestValidator.TOOSHORT + "', not '"  +
        fe.getCode() + "'", fe.getCode().equals(TestValidator.TOOSHORT));

    // raised by second validator
    ObjectError oe = errors.getGlobalError();
    assertEquals("test", oe.getCode());
    assertEquals("testmessage", oe.getDefaultMessage());
  }
View Full Code Here

    final BindingResult errors = createNiceMock(BindingResult.class);
    final String username = ""; //no username specified
    final String password = "password";
    final String confirmPassword = password;
    List<ObjectError> errorList = new ArrayList<ObjectError>();
    final ObjectError error = new ObjectError("username.required", "Username required");

    User.setUsername(username);
    User.setPassword(password);
    User.setConfirmPassword(confirmPassword);
View Full Code Here

    final String username = "canonical"; //specified username already exists in database
    final String password = "password";
    final String confirmPassword = password;
    final User existingUser = new UserImpl();
    List<ObjectError> errorList = new ArrayList<ObjectError>();
    final ObjectError error = new ObjectError("username.exists", "Username already exists");

    User.setUsername(username);
    User.setPassword(password);
    User.setConfirmPassword(confirmPassword);
View Full Code Here

    final BindingResult errors = createNiceMock(BindingResult.class);
    final String username = "u"; //username length less than 2 characters
    final String password = "password";
    final String confirmPassword = password;
    List<ObjectError> errorList = new ArrayList<ObjectError>();
    final ObjectError error = new ObjectError("username.invalid.length", "Username must be atleast 2 characters long");

    User.setUsername(username);
    User.setPassword(password);
    User.setConfirmPassword(confirmPassword);
View Full Code Here

    User.setUsername(username);
    User.setPassword(password);
    User.setConfirmPassword(confirmPassword);

    errorList.add(new ObjectError("password.required", "Password required"));
    errorList.add(new ObjectError("confirmPassword.required", "Confirm password required"));

    expect(errors.hasErrors()).andReturn(true).anyTimes();
    expect(errors.getAllErrors()).andReturn(errorList).anyTimes();
    replay(errors);
    replay(model);
View Full Code Here

TOP

Related Classes of org.springframework.validation.ObjectError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.