Package org.springframework.validation

Examples of org.springframework.validation.ObjectError


    @SuppressWarnings("unchecked")
    @Test
    public void testConstructorWithBindingResult() {
        List<ObjectError> allErrors = new ArrayList<ObjectError>();
        allErrors.add(new ObjectError(OBJECT_NAME, OBJECT_MESSAGE));
        allErrors.add(new FieldError(OBJECT_NAME, FIELD, FIELD_MESSAGE));
       
        FailValidationJsonResponse response = new FailValidationJsonResponse(allErrors);
       
        List<ValidationError> result = (List<ValidationError>) response.getResult();
View Full Code Here


    return name;
  }

  @Override
  public void reject(String errorCode, Object[] errorArgs, String defaultMessage) {
    globalErrors.add(new ObjectError(name, new String[] { errorCode }, errorArgs, defaultMessage));
  }
View Full Code Here

    person.setName("Juergen");
    person.getAddress().setStreet("Juergen's Street");
    BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
    validator.validate(person, result);
    assertEquals(1, result.getErrorCount());
    ObjectError globalError = result.getGlobalError();
    List<String> errorCodes = Arrays.asList(globalError.getCodes());
    assertEquals(2, errorCodes.size());
    assertTrue(errorCodes.contains("NameAddressValid.person"));
    assertTrue(errorCodes.contains("NameAddressValid"));
  }
View Full Code Here

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

   * Extract the error codes from the ObjectError list.
   */
  private void initErrorCodes() {
    this.errorCodes = new String[this.objectErrors.size()];
    for (int i = 0; i < this.objectErrors.size(); i++) {
      ObjectError error = this.objectErrors.get(i);
      this.errorCodes[i] = error.getCode();
    }
  }
View Full Code Here

   */
  private void initErrorMessages() throws NoSuchMessageException {
    if (this.errorMessages == null) {
      this.errorMessages = new String[this.objectErrors.size()];
      for (int i = 0; i < this.objectErrors.size(); i++) {
        ObjectError error = this.objectErrors.get(i);
        this.errorMessages[i] = this.requestContext.getMessage(error, this.htmlEscape);
      }
    }
  }
View Full Code Here

            // as necessary for Hibernate Validator compatibility (non-indexed set path in field)
            BindingResult bindingResult = (BindingResult) errors;
            String nestedField = bindingResult.getNestedPath() + field;
            if ("".equals(nestedField)) {
              String[] errorCodes = bindingResult.resolveMessageCodes(errorCode);
              bindingResult.addError(new ObjectError(
                  errors.getObjectName(), errorCodes, errorArgs, violation.getMessage()));
            }
            else {
              Object invalidValue = violation.getInvalidValue();
              if (!"".equals(field) && (invalidValue == violation.getLeafBean() ||
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: &quot; &#39;".equals(globalError.getDefaultMessage()));
    assertTrue("Global error code not escaped", "GENERAL_ERROR \" '".equals(globalError.getCode()));
    ObjectError globalErrorInList = errors.getGlobalErrors().get(0);
    assertTrue("Same global error in list", globalError.getDefaultMessage().equals(globalErrorInList.getDefaultMessage()));
    ObjectError globalErrorInAllList = 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

    person.setName("Juergen");
    person.getAddress().setStreet("Juergen's Street");
    BeanPropertyBindingResult result = new BeanPropertyBindingResult(person, "person");
    validator.validate(person, result);
    assertEquals(1, result.getErrorCount());
    ObjectError globalError = result.getGlobalError();
    List<String> errorCodes = Arrays.asList(globalError.getCodes());
    assertEquals(2, errorCodes.size());
    assertTrue(errorCodes.contains("NameAddressValid.person"));
    assertTrue(errorCodes.contains("NameAddressValid"));
  }
View Full Code Here

    Object payload = message.getPayload();
    if (isEmptyPayload(payload)) {
      if (annot == null || annot.required()) {
        String paramName = getParameterName(param);
        BindingResult bindingResult = new BeanPropertyBindingResult(payload, paramName);
        bindingResult.addError(new ObjectError(paramName, "@Payload param is required"));
        throw new MethodArgumentNotValidException(message, param, bindingResult);
      }
      else {
        return null;
      }
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.