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.zbo.done.web.OwnerController.java

@RequestMapping(value = "bootstrap/owners/new", method = RequestMethod.POST)
public String create_owner(@Valid Owner owner, BindingResult result) {
    if (result.hasErrors()) {
        return "bootstrap/pages/ownerDetails.jsp";
    } else {//www. j a  va  2 s  .c  om
        this.ownerService.saveOwner(owner);
        return "redirect:/bootstrap/owners/" + owner.getId();
    }
}

From source file:com.fengduo.bee.web.controller.BaseController.java

/**
 * ???//  w  ww  . j a  v a2 s  .  com
 * 
 * @param result
 * @return
 */
public String showFirstErrors(BindingResult result) {
    if (result.hasErrors()) {
        for (FieldError error : result.getFieldErrors()) {
            return error.getDefaultMessage();
        }
    }
    return StringUtils.EMPTY;
}

From source file:com.indusborn.ui.reset.ResetPasswordController.java

/**
 * Process the change password submission and reset the user's password.
 *//*from w  ww . jav a2  s . co m*/
@RequestMapping(value = "/reset", method = RequestMethod.POST, params = "token")
public String changePassword(@RequestParam String token, @Valid ChangePasswordForm form,
        BindingResult formBinding, Model model) {
    if (formBinding.hasErrors()) {
        model.addAttribute("token", token);
        return "reset/changePassword";
    }
    try {
        resetPasswordHelper.resetPassword(token, form.getPassword());
        FlashMap.setSuccessMessage("Your password has been reset");
        return "redirect:/signin";
    } catch (InvalidResetPasswordTokenException e) {
        FlashMap.setErrorMessage("Your reset password session has expired.  Please try again.");
        return "redirect:/reset";
    }
}

From source file:com.test.springmvc.springmvcproject.CommentController.java

@RequestMapping(value = "/{bookId}/add", method = RequestMethod.POST)
public String addComment(@PathVariable Integer bookId, HttpSession session, @Valid CommentaireBean commentaire,
        BindingResult results) {
    if (!results.hasErrors()) {
        //on ajoute l'utilisateur
        final UtilisateurBean utilisateur = (UtilisateurBean) session.getAttribute("utilisateur");
        if (null != utilisateur) {
            commentaire.setUtilisateur(utilisateur);
        } else {/*ww  w . ja  v a 2  s.  c om*/
            try {
                commentaire
                        .setUtilisateur(utilisateurService.getById(ApplicationConstants.IDENTIFIANT_ANNONYME));
            } catch (NoDataFoundException e) {
                return "redirect:/404.do";
            }
        }
        try {
            final BookBean bean = searchService.findById(bookId);
            commentaire.setLivre(bean);
        } catch (NoDataFoundException e) {
            return "redirect:/404.do";
        }
        System.out.println(commentaire.getCommentaire());
        commentaireService.save(commentaire);
    }
    return "redirect:/book/" + bookId + "/show.do";
}

From source file:org.dspace.webmvc.controller.LoginController.java

/**
 * Method to authenticate the user credentials supplied in loginForm.
 * <p/>/*from ww  w . j  a va 2s.co m*/
 * Note that the order of parameters is important - the BindingResult must immediately follow the model attribute
 * being validated.
 *
 * @param context
 * @param loginService
 * @param loginForm
 * @param bindingResult
 * @return
 */
@RequestMapping(params = "submit")
public String processForm(@RequestAttribute Context context, LoginService loginService,
        @Valid LoginForm loginForm, BindingResult bindingResult) {
    if (!bindingResult.hasErrors()) {
        int status = AuthenticationManager.authenticate(context, loginForm.getEmail(), loginForm.getPassword(),
                null, null /*request*/);
        if (status == AuthenticationMethod.SUCCESS) {
            loginService.createUserSession(context, context.getCurrentUser());
            String redirectUrl = loginService.getInterruptedRequestURL();
            return "redirect:" + (StringUtils.isEmpty(redirectUrl) ? "/" : redirectUrl);
        } else {
            bindingResult.addError(new ObjectError("loginForm",
                    new String[] { "InvalidPassword.loginForm", "InvalidPassword" }, null /* arguments */,
                    "default message"));
        }
    }

    return "pages/login";
}

From source file:org.ow2.petals.cloud.vacation.web.mvc.LoginController.java

@RequestMapping(method = RequestMethod.POST)
public ModelAndView doLogin(final @ModelAttribute(USER_ATTRIBUTE) @Valid UserModel user,
        final BindingResult result, final RedirectAttributes redirect) {

    if (result.hasErrors()) {
        return new ModelAndView("pages/login");
    }//from   www .ja  v  a2  s  . c om

    userSession.setUsername(user.username);

    redirect.addFlashAttribute("globalMessage", "Successfully logged as " + user.username);

    return new ModelAndView("redirect:/");
}

From source file:cz.PA165.vozovyPark.controller.VehicleController.java

@RequestMapping(value = "/vehicle/update/{vehicleId}", method = RequestMethod.POST)
public String updateVehicle(@ModelAttribute("vehicle") VehicleDTO vehicle, @PathVariable("vehicleId") Long id,
        BindingResult result) {

    if (result.hasErrors()) {
        return "/vehicle/vehicleUpdateForm";
    }/*from w  w  w.  ja  v  a  2  s  .  c  om*/
    if (id == null) {
        return "/vehicle/vehicleUpdateForm";
    }
    vehicleService.updateVehicle(vehicle);
    return "redirect:/vehicle/allVehicles";
}

From source file:JavaMvc.Controllers.SignupController.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String showSignupForm(Model model, @ModelAttribute SignupCommand command, BindingResult errors) {
    signupValidator.validate(command, errors);

    if (errors.hasErrors()) {
        return showSignupForm(model, command);
    }/*w  ww .j av  a  2s .co m*/

    // Create the user
    userService.createUser(command.getUsername(), command.getEmail(), command.getPassword());

    // Login the newly created user
    SecurityUtils.getSubject().login(new UsernamePasswordToken(command.getUsername(), command.getPassword()));

    return "redirect:/home";
}

From source file:org.energyos.espi.datacustodian.web.custodian.RetailCustomerUsagePointControllerTests.java

@Test
public void create_givenInValidInput_displaysFormView() {
    AssociateUsagePointController.UsagePointForm usagePointForm = new AssociateUsagePointController.UsagePointForm();

    BindingResult result = mock(BindingResult.class);
    when(result.hasErrors()).thenReturn(true);

    assertEquals("/custodian/retailcustomers/usagepoints/form", controller.create(1L, usagePointForm, result));
}

From source file:org.homiefund.web.controllers.HomeController.java

@PostMapping("/invite/")
public String invite(@ModelAttribute InviteForm inviteForm, BindingResult bindingResult, Model model) {
    if (bindingResult.hasErrors()) {
        return "home.entry";
    } else {//from   w w  w  .  j av  a2  s. co m
        HomeDTO home = new HomeDTO();
        home.setId(inviteForm.getHomeID());
        inviteService.sendInvite(home, inviteForm.getEmail());

        return "redirect:/auth/home/" + home.getId() + "/";
    }
}