Example usage for org.springframework.validation BindingResult addError

List of usage examples for org.springframework.validation BindingResult addError

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult addError.

Prototype

void addError(ObjectError error);

Source Link

Document

Add a custom ObjectError or FieldError to the errors list.

Usage

From source file:org.easyj.rest.controller.AbstractController.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(TypeMismatchException.class)
public ModelAndView handleTypeMismatch(TypeMismatchException e) {
    BindingResult result = createBindingResult(getClass());

    result.addError(new FieldError("param.bind", e.getRequiredType().getSimpleName(), e.getValue(), true, null,
            null, "error.param.bind.type"));

    return configMAV(null, result, "errors/badrequest");
}

From source file:org.easyj.rest.controller.GenericEntityController.java

public <T> void bindValidatorErrors(Set<ConstraintViolation<T>> violations, BindingResult result) {
    if (violations != null) {
        for (ConstraintViolation<T> violation : violations) {
            result.addError(new FieldError(result.getObjectName(), violation.getPropertyPath().toString(),
                    violation.getInvalidValue(), false, null, null, violation.getMessageTemplate()));
        }/*w  ww .  j  a  v a  2  s .c  o  m*/
    }
}

From source file:com.asual.summer.core.spring.ExtendedServletRequestDataBinder.java

public BindingResult getBindingResult() {
    BindingResult result = super.getInternalBindingResult();
    if ((RequestUtils.getRequest() != null && RequestUtils.isValidation()) && !result.hasErrors()) {
        result.addError(new ObjectError("validation", "success"));
    }/*ww w  .j a v  a  2 s  . c o  m*/
    return result;
}

From source file:org.kew.rmf.matchconf.web.DictionaryController.java

public void customValidation(Dictionary dict, BindingResult br) {
    if (!FieldValidator.validSlug(dict.getName())) {
        br.addError(new ObjectError("dict.name",
                "The name has to be set and can only contain ASCII letters and/or '-' and/or '_'"));
    }//from w ww .j  av a2  s  .co m
}

From source file:com.kinglcc.spring.jms.core.Jackson2PayloadArgumentResolver.java

private void bindEmptyPayloadError(MethodParameter parameter, Message<?> message, Object payload) {
    String paramName = getParameterName(parameter);
    BindingResult bindingResult = new BeanPropertyBindingResult(payload, paramName);
    bindingResult.addError(new ObjectError(paramName, "@Payload param is required"));
    throw new MethodArgumentNotValidException(message, parameter, bindingResult);
}

From source file:org.kew.rmf.matchconf.web.CustomWireController.java

public void customValidation(String configName, Wire wire, BindingResult br) {
    if (!FieldValidator.validSlug(wire.getName())) {
        br.addError(
                new ObjectError("wire.name", "The name can only contain ASCII letters and/or '-' and/or '_'"));
    }/*from ww  w.j  av a2 s.  c o  m*/
}

From source file:org.kew.rmf.matchconf.web.CustomReporterController.java

public void customValidation(String configName, Reporter reporter, BindingResult br) {
    if (!FieldValidator.validSlug(reporter.getName())) {
        br.addError(new ObjectError("reporter.name",
                "The name has to be set and can only contain ASCII letters and/or '-' and/or '_'"));
    }/*  www  . java  2 s.c  om*/
}

From source file:org.kew.rmf.matchconf.web.CustomMatcherController.java

public void customValidation(String configName, Matcher matcher, BindingResult br) {
    if (!FieldValidator.validSlug(matcher.getName())) {
        br.addError(new ObjectError("matcher.name",
                "The name has to be set and can only contain ASCII letters and/or '-' and/or '_'"));
    }//from  w  ww .  j  a  v a  2  s  . c  o  m
}

From source file:org.kew.rmf.matchconf.web.CustomTransformerController.java

public void customValidation(String configName, Transformer transformer, BindingResult br) {
    if (!FieldValidator.validSlug(transformer.getName())) {
        br.addError(new ObjectError("transformer.name",
                "The name has to be set and can only contain ASCII letters and/or '-' and/or '_'"));
    }/*from w w  w .j  a v a2  s  .  c  o m*/
}

From source file:org.socialsignin.springsocial.security.signup.AbstractSignUpController.java

private boolean isUserNameValid(String userName, BindingResult errors) {
    if (userName == null || userName.trim().length() == 0) {
        errors.addError(new FieldError("signUpForm", "userName", "Please choose a username"));
        return false;
    } else {/*from   www  . jav a2 s .co  m*/
        return true;
    }
}