Example usage for org.springframework.validation BindingResult hasErrors

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

Introduction

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

Prototype

boolean hasErrors();

Source Link

Document

Return if there were any errors.

Usage

From source file:org.ng200.openolympus.controller.admin.AdministrativeChangePasswordController.java

@RequestMapping(method = RequestMethod.POST)
public String changePassword(Model model, @Valid final PasswordChangeDto userDto,
        final BindingResult bindingResult, @PathVariable(value = "user") User user) {
    if (bindingResult.hasErrors()) {
        model.addAttribute("hideOldPassword", true);
        model.addAttribute("postUrl", "/admin/user/" + user.getId() + "/changePassword");
        return "user/changePassword";
    }//from   w ww  .  j  ava2 s . c o m
    if (!userDto.getPassword().equals(userDto.getPasswordConfirmation())) {
        bindingResult.rejectValue("passwordConfirmation", "",
                "user.changePassword.form.errors.passwordConfirmationDoesntMatch");
    }
    if (bindingResult.hasErrors()) {
        model.addAttribute("hideOldPassword", true);
        model.addAttribute("postUrl", "/admin/user/" + user.getId() + "/changePassword");
        return "user/changePassword";
    }

    user.setPassword(this.passwordEncoder.encode(userDto.getPassword()));
    this.userRepository.save(user);
    return "redirect:/admin/users";
}

From source file:cn.guoyukun.spring.web.controller.BaseController.java

/**
 * ?//from  ww w . j a  v  a 2  s  . com
 * ?true
 *
 * @param m
 * @param result
 * @return
 */
protected boolean hasError(M m, BindingResult result) {
    Assert.notNull(m);
    return result.hasErrors();
}

From source file:com.kzk.stsm.controller.SeedStarterMngController.java

@RequestMapping(value = "/seedstartermng", params = { "save" })
public String saveSeedstarter(final SeedStarter seedStarter, final BindingResult bindingResult,
        final ModelMap model) {
    if (bindingResult.hasErrors()) {
        return "seedstartermng";
    }//from w w w .  j av a 2 s  .  c om
    this.seedStarterService.add(seedStarter);
    model.clear();
    return "redirect:./seedstartermng";
}

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

@RequestMapping(value = "/pass", params = "form", method = RequestMethod.POST)
public ModelAndView changePass(User user, BindingResult bindingResult, Principal principal,
        RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("account", "formErrors", bindingResult.getAllErrors());
    }/* w w w. jav a  2s  . c  o  m*/
    User currentUser = userRepo.findBySsoId(principal.getName());
    currentUser.setPassword(passEncoder.encode(user.getPassword()));
    userRepo.save(currentUser);
    redirectAttributes.addFlashAttribute("globalMessage", "Password changed");
    return new ModelAndView("redirect:/account");
}

From source file:com.sastix.cms.server.utils.ValidationHelper.java

public void validate(BindingResult result) throws ContentValidationException {
    if (result == null) {
        return;//  w ww . ja v a 2 s .com
    }
    if (!result.hasErrors()) {
        return;
    }
    String message = createMessage(result.getFieldErrors());
    LOG.trace("Field errors: " + message);
    throw new ContentValidationException(message);
}

From source file:com.dub.skoolie.web.controller.system.schedule.events.SystemDistrictEventController.java

@RequestMapping(value = "/system/schedule/events/district", method = RequestMethod.POST)
public ModelAndView addDistrictEvent(@Valid DistrictEventBean districtEventBean, BindingResult result,
        Model model, HttpServletRequest request) {
    String referrer = request.getHeader("Referer");
    if (result.hasErrors()) {
        if (!referrer.equals("/system/schedule/events/district")) {
            return new ModelAndView("redirect:" + referrer);
        }//w w  w . j av  a  2s.  com
        return new ModelAndView("system/schedule/events/index");
    }
    uiDistrictEventServiceImpl.addDistrictEvent(districtEventBean);
    return new ModelAndView("system/schedule/events/index");
}

From source file:com.dub.skoolie.web.controller.system.schedule.events.SystemUserEventController.java

@RequestMapping(value = "/system/schedule/events/user", method = RequestMethod.POST)
public ModelAndView addUserEvent(@Valid UserEventBean userEventBean, BindingResult result, Model model,
        HttpServletRequest request) {/*from w ww.j av  a2 s. c  o m*/
    String referrer = request.getHeader("Referer");
    if (result.hasErrors()) {
        if (!referrer.equals("/system/schedule/events/user")) {
            return new ModelAndView("redirect:" + referrer);
        }
        return new ModelAndView("system/schedule/events/index");
    }
    uiUserEventServiceImpl.addUserEvent(userEventBean);
    return new ModelAndView("system/schedule/events/index");
}

From source file:org.terasoluna.tourreservation.app.managecustomer.ManageCustomerController.java

/**
 * shows the confirmation screen before registering a new customer
 * @param form/*from  w  w  w . j  a v a  2 s  .co m*/
 * @param result
 * @return
 */
@TransactionTokenCheck(value = "create", type = TransactionTokenType.BEGIN)
@RequestMapping(value = "create", method = RequestMethod.POST, params = "confirm")
public String createConfirm(@Validated CustomerForm form, BindingResult result) {
    if (result.hasErrors()) {
        return createRedo(form);
    }
    return "managecustomer/createConfirm";
}

From source file:com.lixiaocong.rest.CommentController.java

@RequestMapping(method = RequestMethod.POST)
public Map<String, Object> post(@RequestParam long articleId, @RequestBody @Valid CommentForm comment,
        BindingResult result, Principal principal) throws RestParamException {
    if (result.hasErrors())
        throw new RestParamException();
    User user = userService.getByUsername(principal.getName());

    commentService.create(articleId, user.getId(), comment.getContent());
    return ResponseMsgFactory.createSuccessResponse();
}

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

@RequestMapping(value = "/details", params = "form", method = RequestMethod.POST)
public ModelAndView changeDetails(User user, BindingResult bindingResult, Principal principal,
        RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        return new ModelAndView("account", "formErrors", bindingResult.getAllErrors());
    }/*from w w  w. j a  v a2s .  c  om*/
    User currentUser = userRepo.findBySsoId(principal.getName());
    currentUser.setEmail(user.getEmail());
    currentUser.setFirstName(user.getFirstName());
    currentUser.setLastName(user.getLastName());
    userRepo.save(currentUser);
    redirectAttributes.addFlashAttribute("globalMessage", "Details changed");
    return new ModelAndView("redirect:/account");
}