Example usage for org.springframework.validation BindingResult getAllErrors

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

Introduction

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

Prototype

List<ObjectError> getAllErrors();

Source Link

Document

Get all errors, both global and field ones.

Usage

From source file:cherry.foundation.util.MessageSourceUtil.java

public static List<String> getMessageList(BindingResult binding) {
    Locale locale = LocaleContextHolder.getLocale();
    List<String> list = new ArrayList<>(binding.getAllErrors().size());
    for (ObjectError objectError : binding.getAllErrors()) {
        list.add(messageSource.getMessage(objectError, locale));
    }/*from  w  w w  .  j  av  a  2  s.com*/
    return list;
}

From source file:org.zht.framework.validate.ValidateHandler.java

public static ValidateResult handle(BindingResult result) {
    ValidateResult retVal = new ValidateResult();
    if (result.hasErrors()) {
        List<ObjectError> list = result.getAllErrors();
        ObjectError oe = list.get(0);//w  w w.  j a v  a 2s. co  m
        retVal.setMessage(oe.getDefaultMessage());
        retVal.setResult(false);
    } else {
        retVal.setResult(true);
    }
    return retVal;
}

From source file:net.maritimecloud.identityregistry.utils.ValidateUtil.java

public static void hasErrors(BindingResult bindingResult, HttpServletRequest request)
        throws McBasicRestException {
    if (bindingResult.hasErrors()) {
        String combinedErrMsg = "";
        for (ObjectError err : bindingResult.getAllErrors()) {
            if (combinedErrMsg.length() != 0) {
                combinedErrMsg += ", ";
            }/*from  www . ja v a2s. c om*/
            combinedErrMsg += err.getDefaultMessage();
        }
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, combinedErrMsg, request.getServletPath());
    }
}

From source file:com.google.ie.dto.ViewStatus.java

/**
 * @param errors//from   w w  w .  ja  v a  2  s  .co  m
 */
public static ViewStatus createProjectErrorViewStatus(BindingResult errors) {
    ViewStatus viewStatus = new ViewStatus();
    log.warn("Project object has " + errors.getErrorCount() + " validation errors");
    viewStatus.setStatus(WebConstants.ERROR);
    for (Iterator<ObjectError> iterator = errors.getAllErrors().iterator(); iterator.hasNext();) {
        ObjectError objError = iterator.next();
        if (objError instanceof FieldError) {
            FieldError fieldError = (FieldError) objError;
            viewStatus.addMessage(WebConstants.ERROR,
                    fieldError.getField() + " - " + fieldError.getDefaultMessage());
            log.warn("Error found in field: " + fieldError.getField() + " Message :"
                    + objError.getDefaultMessage());
        } else {
            viewStatus.addMessage(WebConstants.ERROR, objError.getDefaultMessage());
            log.warn(" Message :" + objError.getDefaultMessage());
        }

    }
    return viewStatus;

}

From source file:org.zht.framework.validate.ValidateHandler.java

public static String getDefaultError(BindingResult result) {
    if (result.hasErrors()) {
        List<FieldError> fieldEist = result.getFieldErrors();
        if (fieldEist != null && fieldEist.size() > 0) {
            FieldError fieldError = fieldEist.get(0);
            fieldError.getCode();//w ww. jav  a2s  .  co m
            String prefix = "\r\n" + "???";
            String value = "{" + (fieldError.getRejectedValue() == null ? " " : fieldError.getRejectedValue())
                    + "}";
            String message = "" + fieldError.getDefaultMessage();
            return prefix + "" + value + "\r\n" + message;
        } else {
            List<ObjectError> allErrorlist = result.getAllErrors();
            ObjectError oe = allErrorlist.get(0);
            return "" + oe.getDefaultMessage();
        }
    } else {
        return null;
    }
}

From source file:org.opentides.util.CrudUtil.java

/**
 * Converts the binding error messages to list of MessageResponse
 * /*from   www.  j a  v a  2 s  .  c  o m*/
 * @param bindingResult
 */
public static List<MessageResponse> convertErrorMessage(BindingResult bindingResult, Locale locale,
        MessageSource messageSource) {
    List<MessageResponse> errorMessages = new ArrayList<MessageResponse>();
    if (bindingResult.hasErrors()) {
        for (ObjectError error : bindingResult.getAllErrors()) {
            MessageResponse message = null;
            if (error instanceof FieldError) {
                FieldError ferror = (FieldError) error;
                message = new MessageResponse(MessageResponse.Type.error, error.getObjectName(),
                        ferror.getField(), error.getCodes(), error.getArguments());
            } else
                message = new MessageResponse(MessageResponse.Type.error, error.getObjectName(), null,
                        error.getCodes(), error.getArguments());
            message.setMessage(messageSource.getMessage(message, locale));
            errorMessages.add(message);
        }
    }
    return errorMessages;
}

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

public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
    super.processPropertyAccessException(ex, bindingResult);
    Object[] arguments = bindingResult.getAllErrors().get(bindingResult.getErrorCount() - 1).getArguments();
    arguments[1] = ExceptionUtils.getRootCause(ex).getMessage();
}

From source file:com.create.controller.BeanValidatorErrorHandler.java

@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)// w w  w  . j  av  a 2 s.  c  om
@ResponseBody
public ValidationResult<?> processValidationErrors(MethodArgumentNotValidException exception) {
    final BindingResult result = exception.getBindingResult();
    final List<ObjectError> fieldErrors = result.getAllErrors();
    final List<?> targets = getTargets(result);
    return processValidationErrors(targets, fieldErrors);
}

From source file:com.acc.storefront.controllers.misc.AddToCartController.java

protected String getViewWithBindingErrorMessages(final Model model, final BindingResult bindingErrors) {
    for (final ObjectError error : bindingErrors.getAllErrors()) {
        if (isTypeMismatchError(error)) {
            model.addAttribute(ERROR_MSG_TYPE, QUANTITY_INVALID_BINDING_MESSAGE_KEY);
        } else {/*ww  w  . ja  v  a 2s .c  om*/
            model.addAttribute(ERROR_MSG_TYPE, error.getDefaultMessage());
        }
    }
    return ControllerConstants.Views.Fragments.Cart.AddToCartPopup;
}

From source file:com.pw.ism.controllers.MainController.java

@RequestMapping(value = "/create", method = RequestMethod.POST)
public ModelAndView create(@Valid User user, BindingResult result, RedirectAttributes redirect) {
    if (result.hasErrors()) {
        return new ModelAndView("/create", "formErrors", result.getAllErrors());
    }/*from   w w  w  . ja  v a 2 s.c om*/
    user.setState(false);
    System.out.println("user sso_id " + user.getSsoId());
    userRepo.save(user);
    redirect.addFlashAttribute("globalMessage", "Successfully created a new account");
    return new ModelAndView("redirect:/");
}