Package org.springframework.validation

Examples of org.springframework.validation.BindingResult.addError()


            // 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


                // Possibly a bean constraint with property path: retrieve the actual property value.
                // However, explicitly avoid this for "address[]" style paths that we can't handle.
                invalidValue = bindingResult.getRawFieldValue(field);
              }
              String[] errorCodes = bindingResult.resolveMessageCodes(errorCode, field);
              bindingResult.addError(new FieldError(
                  errors.getObjectName(), nestedField, invalidValue, false,
                  errorCodes, errorArgs, violation.getMessage()));
            }
          }
          else {
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


    for (String key : raw.keySet()) {
      int separator = key.indexOf(OPTION_SEPARATOR);
      if (separator == -1) {
        bindingResult.addError(new FieldError("options", key, String.format("unsupported option '%s'", key)));
        continue;
      }
      String prefix = key.substring(0, separator);
      String suffix = key.substring(separator + OPTION_SEPARATOR.length());
      Map<String, String> map = valuesWithoutPrefix.get(prefix);
View Full Code Here

      }
      String prefix = key.substring(0, separator);
      String suffix = key.substring(separator + OPTION_SEPARATOR.length());
      Map<String, String> map = valuesWithoutPrefix.get(prefix);
      if (map == null) {
        bindingResult.addError(new FieldError("options", key, String.format("unsupported option '%s'", key)));
        continue;
      }
      map.put(suffix, raw.get(key));
    }
View Full Code Here

    if (copy.size() > 0) {
      // We're just interested in a container for errors
      BindingResult bindingResult = new MapBindingResult(new HashMap<String, Object>(), "flattened");
      for (String pty : copy.keySet()) {
        bindingResult.addError(new FieldError("flattened", pty, String.format(
            "option named '%s' is not supported", pty)));
      }
      throw new BindException(bindingResult);
    }
View Full Code Here

  @Test
  public void extractBindingResultErrors() throws Exception {
    BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a",
        "b"), "objectName");
    bindingResult.addError(new ObjectError("c", "d"));
    BindException ex = new BindException(bindingResult);
    this.request.setAttribute("javax.servlet.error.exception", ex);
    Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(
        this.requestAttributes, false);
    assertThat(attributes.get("message"), equalTo((Object) ("Validation failed for "
View Full Code Here

  }
 
  public BindingResult getBindingResult() {
    BindingResult result = super.getInternalBindingResult();
    if ((RequestUtils.getRequest() != null && RequestUtils.isValidation()) && !result.hasErrors()) {
      result.addError(new ObjectError("validation", "success"));
    }
    return result;
  }

}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.