List of usage examples for org.springframework.validation BindingResult hasErrors
boolean hasErrors();
From source file:org.xinta.eazycode.components.shiro.web.controller.SignupController.java
@RequestMapping(value = "/signup", method = RequestMethod.POST) public String showSignupForm(Model model, @ModelAttribute SignupVO command, BindingResult errors) { signupValidator.validate(command, errors); if (errors.hasErrors()) { return showSignupForm(model, command); }// ww w. java2 s .c om // Create the user userService.createUser(command.getLoginName(), command.getName(), command.getEmail(), command.getPassword()); // Login the newly created user SecurityUtils.getSubject().login(new UsernamePasswordToken(command.getLoginName(), command.getPassword())); return "redirect:/home.do"; }
From source file:se.omegapoint.facepalm.client.controllers.UserController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public String register(final @Valid RegisterCredentials credentials, final BindingResult bindingResult, final Model model) { if (bindingResult.hasErrors()) { credentials.resetPasswords();/*from w ww . j a va 2s .c o m*/ return "login"; } final OperationResult result = userAdapter.registerNewUser(credentials); if (result.isSuccess()) { model.addAttribute("message", "User successfully created, please login"); // TODO [dh] Internationalization model.addAttribute("registerCredentials", new RegisterCredentials()); return "login"; // FIXME [dh] Should be redirect with flash attributes, but i simply cannot get it working tonight, why?! } else { model.addAttribute("registerMessage", result.message()); credentials.resetPasswords(); return "login"; } }
From source file:com.gym.controller.UsuarioController.java
@RequestMapping(value = "/registro", method = RequestMethod.POST) public String registro(Map<String, Object> map, HttpServletRequest request, @Valid Usuario usuario, BindingResult result) { if (result.hasErrors()) { map.put("edad", cargaEdad()); map.put("altura", cargaAltura()); map.put("peso", cargaPeso()); return "registro"; }//from ww w . jav a2s . c o m usuarioService.addUsuario(usuario); //AccesoUsuario accesoOK = accesoUsuarioService.getAccesoUsuario(Usuario.getLogin(),accesoUsuario.getPassword()); return "index"; }
From source file:cz.muni.fi.mir.controllers.UserRoleController.java
@Secured("ROLE_ADMINISTRATOR") @RequestMapping(value = { "/create", "/create/" }, method = RequestMethod.POST) @SiteTitle("{navigation.userrole.create}") public ModelAndView createUserRoleSubimt(@Valid @ModelAttribute("userRoleForm") UserRoleForm userRoleForm, BindingResult result, Model model) { if (result.hasErrors()) { ModelMap mm = new ModelMap(); mm.addAttribute(model);//from ww w . j ava 2 s . co m mm.addAttribute("userRoleForm", userRoleForm); return new ModelAndView("userrole_create", mm); } else { userRoleService.createUserRole(mapper.map(userRoleForm, UserRole.class)); return new ModelAndView("redirect:/userrole/list/"); } }
From source file:cz.muni.fi.mir.controllers.UserRoleController.java
@Secured("ROLE_ADMINISTRATOR") @RequestMapping(value = { "/edit", "/edit/" }, method = RequestMethod.POST) @SiteTitle("{entity.userrole.edit}") public ModelAndView editUserRoleSubimt(@Valid @ModelAttribute("userRoleForm") UserRoleForm userRoleForm, BindingResult result, Model model) { if (result.hasErrors()) { ModelMap mm = new ModelMap(); mm.addAttribute(model);// www . ja v a2 s .co m mm.addAttribute("userRoleForm", userRoleForm); return new ModelAndView("user_edit", mm); } else { userRoleService.updateUserRole(mapper.map(userRoleForm, UserRole.class)); return new ModelAndView("redirect:/userrole/list/"); } }
From source file:ems.emsystem.controller.EmployeeController.java
@RequestMapping(value = { "/edit" }, method = RequestMethod.POST) public String editEmployee(@Valid Employee emp, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { List<Department> depList = departmentService.getDepartments(); model.addAttribute("departments", depList); return "editEmployee"; }/*from ww w . j a v a2 s.c o m*/ employeeService.editEmployee(emp); return "redirect: /" + emp.getId(); }
From source file:wad.booklibrary.controller.UserController.java
@RequestMapping(value = "userform", method = RequestMethod.POST) public String create(@Valid @ModelAttribute(value = "user") User user, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model) { if (bindingResult.hasErrors()) { return "userform"; }/* w ww. j ava2 s .co m*/ if (userService.findByUsername(user.getUsername()) != null) { model.addAttribute("error", "Username is already in use."); user.setUsername(""); return "userform"; } user.setEnabled(1); user.setAuthority("user"); userService.create(user); redirectAttributes.addFlashAttribute("message", "New user registered!"); return "redirect:/app/userform"; }
From source file:com.example.session.app.account.AccountUpdateController.java
@RequestMapping(value = "update", params = "form2") public String showUpdateForm2(@Validated(Wizard1.class) AccountUpdateForm form, BindingResult result) { if (result.hasErrors()) { return "account/updateForm1"; }// ww w. ja v a 2 s. c om return "account/updateForm2"; }
From source file:com.example.session.app.account.AccountUpdateController.java
@RequestMapping(value = "update", params = "confirm") public String confirmUpdate(@Validated(Wizard2.class) AccountUpdateForm form, BindingResult result) { if (result.hasErrors()) { return "account/updateForm2"; }/*w w w .j a va 2s. c om*/ return "account/updateConfirm"; }
From source file:com.neeti.neg.controller.MainController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public String saveRegisterUser(@Validated({ Default.class }) RegisterUser registerUser, BindingResult result, Model m) {/*www.jav a 2 s . c om*/ if (!result.hasErrors()) { //check for valid email Id (username) from database boolean validUserName, validGameId; validUserName = registerUserService.checkUserByUserName(registerUser.getGroupName()); validGameId = registerUserService.checkGameRefId(registerUser.getGameRefId(), registerUser.getGamePassword()); if (validUserName) { m.addAttribute("regmsg", messageSource.getMessage("UserNameExists", null, null)); } else if (!validGameId) { m.addAttribute("regmsg", messageSource.getMessage("GameRefIdDNE", null, null)); } else { //save user String hashedPassword = UtilityService.encodePassword(registerUser.getGroupPassword()); registerUser.setGroupPassword(hashedPassword); registerUser.setEnabled(Constant.USER_ENABLED); List<UserRole> listUserRole = new ArrayList<>(); listUserRole.add(new UserRole(Constant.UserRoleEnum.USERROLE_PLAYER.getValue())); registerUser.setUserRoleList(listUserRole); logger.debug("Before registering user for username [" + registerUser.getGroupName() + "]"); registerUserService.createRegisterUser(registerUser); logger.info("Register username [" + registerUser.getGroupName() + "] Successful"); m.addAttribute("regmsg", registerUser.getGroupName() + ": Registered Successfully"); //clear form values registerUser.emptyFieldValues(); } } return "register"; }