List of usage examples for org.springframework.validation BindingResult getModel
Map<String, Object> getModel();
From source file:org.easyj.rest.controller.AbstractController.java
protected ModelAndView configMAV(Object data, BindingResult result, String viewName) { ModelAndView mav = new ModelAndView(); if (result != null && result.hasErrors()) { String resultModel = EasyView.BINDING_RESULT; for (String modelKey : result.getModel().keySet()) { if (result.getModel().get(modelKey) instanceof Errors) { resultModel = modelKey;/*from ww w .j av a2 s .co m*/ break; } } mav.addObject(resultModel, result); } if (data != null) { mav.addObject(EasyView.PROPERTY_EXCLUSIONS, getExclusions()); mav.addObject(EasyView.DATA, data); } if (viewName != null && !viewName.isEmpty()) { mav.setViewName(viewName); } return mav; }
From source file:com.hihsoft.baseclass.web.controller.javahihBaseController.java
/** * .,??model. /*from w w w . j a v a 2 s . c o m*/ * {@link #onSave(HttpServletRequest,HttpServletResponse,ModelAndView,boolean)} * . * * @param request * the request * @param result * the result * @param mav * the mav * @param viewName * the view name * @return the model and view */ @RequestMapping(params = "method=bindError") protected ModelAndView bindError(final HttpServletRequest request, final BindingResult result, final ModelAndView mav, final String viewName) { mav.setViewName(viewName); mav.addAllObjects(result.getModel()); mav.addAllObjects(referenceData(request)); return mav; }
From source file:net.duckling.ddl.web.controller.team.CreateTeamController.java
private ModelAndView validateCreateTeam(TeamForm teamForm, BindingResult br, HttpServletRequest request, HttpServletResponse response) {/*ww w . j a va2s .c om*/ ModelAndView result = null; // String checkCode = request.getParameter("checkCode"); // boolean re = PictureCheckCodeUtil.checkCode(request, checkCode, // "teamType", true); // if (!re) { // result = init(request,teamForm); // result.addObject("checkError", "???"); // } if (StringUtil.illCharCheck(request, null, "teamDescription")) { result = init(request, teamForm); result.addObject("teamDescriptionError", "???:?\\ /*<>|\":"); } if (result == null && br.hasErrors()) { VWBContext context = this.getVWBContext(request); result = layout(".aone.portal", context, "/jsp/aone/team/createTeam.jsp"); ; result.getModel().putAll(br.getModel()); } return result; }
From source file:org.jasig.cas.services.web.RegisteredServiceSimpleFormControllerTests.java
@Test public void verifyAddRegisteredServiceNoValues() throws Exception { final BindingResult result = mock(BindingResult.class); when(result.getModel()).thenReturn(new HashMap<String, Object>()); when(result.hasErrors()).thenReturn(true); final ModelMap model = new ModelMap(); this.controller.onSubmit(mock(RegisteredService.class), result, model, new MockHttpServletRequest()); assertTrue(result.hasErrors());//w ww . j a va 2 s . c o m }
From source file:org.jasig.cas.services.web.RegisteredServiceSimpleFormControllerTests.java
@Test public void verifyEmptyServiceWithModelAttributesRestored() throws Exception { final BindingResult result = mock(BindingResult.class); when(result.getModel()).thenReturn(new HashMap<String, Object>()); when(result.hasErrors()).thenReturn(true); final MockRegisteredService svc = new MockRegisteredService(); svc.setDescription(null);/*from w ww . j av a 2 s .c o m*/ svc.setServiceId(null); final ModelMap model = new ModelMap(); this.controller.onSubmit(svc, result, model, new MockHttpServletRequest()); assertTrue(model.containsAttribute("availableAttributes")); assertTrue(model.containsAttribute("availableUsernameAttributes")); assertTrue(model.containsAttribute("pageTitle")); }
From source file:org.jtalks.jcommune.web.controller.UserController.java
/** * Register {@link org.jtalks.jcommune.model.entity.JCUser} from populated in form {@link RegisterUserDto}. * <p/>/*w w w .j av a2 s .c o m*/ * todo: redirect to the latest url we came from instead of root * * @param registerUserDto {@link RegisterUserDto} populated in form * @param request Servlet request. * @param locale to set currently selected language as user's default * @return redirect to / if registration successful or back to "/registration" if failed */ @RequestMapping(value = "/user/new", method = RequestMethod.POST) public ModelAndView registerUser(@ModelAttribute("newUser") RegisterUserDto registerUserDto, HttpServletRequest request, Locale locale) { if (isHoneypotCaptchaFilled(registerUserDto, getClientIpAddress(request))) { return new ModelAndView(REG_SERVICE_HONEYPOT_FILLED_ERROR_URL); } Map<String, String> registrationPlugins = getRegistrationPluginsHtml(request, locale); BindingResult errors; try { registerUserDto.getUserDto().setLanguage(Language.byLocale(locale)); errors = authenticator.register(registerUserDto); } catch (NoConnectionException e) { return new ModelAndView(REG_SERVICE_CONNECTION_ERROR_URL); } catch (UnexpectedErrorException e) { return new ModelAndView(REG_SERVICE_UNEXPECTED_ERROR_URL); } if (errors.hasErrors()) { ModelAndView mav = new ModelAndView(REGISTRATION); mav.addObject("registrationPlugins", registrationPlugins); mav.addAllObjects(errors.getModel()); return mav; } return new ModelAndView(AFTER_REGISTRATION); }
From source file:org.orcid.frontend.web.controllers.ManageProfileController.java
@RequestMapping(value = { "/security-question", "/change-security-question" }, method = RequestMethod.POST) public ModelAndView updateWithChangedSecurityQuestion( @ModelAttribute("changeSecurityQuestionForm") @Valid ChangeSecurityQuestionForm changeSecurityQuestionForm, BindingResult bindingResult) { if (bindingResult.hasErrors()) { ModelAndView changeSecurityDetailsView = new ModelAndView("change_security_question"); changeSecurityDetailsView.addAllObjects(bindingResult.getModel()); changeSecurityDetailsView.addObject(changeSecurityQuestionForm); return changeSecurityDetailsView; }//www.j a v a 2s.co m OrcidProfile profile = getEffectiveProfile(); profile.setSecurityQuestionAnswer(changeSecurityQuestionForm.getSecurityQuestionAnswer()); profile.getOrcidInternal().getSecurityDetails() .setSecurityQuestionId(new SecurityQuestionId(changeSecurityQuestionForm.getSecurityQuestionId())); orcidProfileManager.updateSecurityQuestionInformation(profile); ModelAndView changeSecurityDetailsView = populateChangeSecurityDetailsViewFromUserProfile( changeSecurityQuestionForm); changeSecurityDetailsView.addObject("securityQuestionSaved", true); return changeSecurityDetailsView; }
From source file:org.orcid.frontend.web.controllers.ManageProfileController.java
@RequestMapping(value = "/save-bio-settings", method = RequestMethod.POST) public ModelAndView saveEditedBio(HttpServletRequest request, @Valid @ModelAttribute("changePersonalInfoForm") ChangePersonalInfoForm changePersonalInfoForm, BindingResult bindingResult, RedirectAttributes redirectAttributes) { ModelAndView manageBioView = new ModelAndView("redirect:/account/manage-bio-settings"); for (String keyword : changePersonalInfoForm.getKeywordsAsList()) { if (keyword.length() > ChangePersonalInfoForm.KEYWORD_MAX_LEN) { bindingResult.rejectValue("keywordsDelimited", "Length.changePersonalInfoForm.keywordsDelimited"); break; }/*from w w w.j a v a 2 s . c om*/ } if (bindingResult.hasErrors()) { ModelAndView erroredView = new ModelAndView("manage_bio_settings"); // If an error happens and the user doesnt have any website, // the privacy selector for websites dissapears. // In order to fix this, if the ChangePersonalInfoForm doesnt have // any researcher url, we add a new one with an empty list, which // is different than null ResearcherUrls Map<String, Object> model = bindingResult.getModel(); if (changePersonalInfoForm.getSavedResearcherUrls() == null) { changePersonalInfoForm.setSavedResearcherUrls(new ResearcherUrls()); } model.put("changePersonalInfoForm", changePersonalInfoForm); erroredView.addAllObjects(bindingResult.getModel()); return erroredView; } OrcidProfile profile = getEffectiveProfile(); // Update profile with values that comes from user request changePersonalInfoForm.mergeOrcidBioDetails(profile); // Update profile on database profileEntityManager.updateProfile(profile); String orcid = profile.getOrcidIdentifier().getPath(); // Update other names on database OtherNames otherNames = profile.getOrcidBio().getPersonalDetails().getOtherNames(); otherNameManager.updateOtherNames(orcid, otherNames); // Update keywords on database Keywords keywords = profile.getOrcidBio().getKeywords(); profileKeywordManager.updateProfileKeyword(orcid, keywords); // Update researcher urls on database ResearcherUrls researcherUrls = profile.getOrcidBio().getResearcherUrls(); boolean hasErrors = researcherUrlManager.updateResearcherUrls(orcid, researcherUrls); // TODO: The researcherUrlManager will not store any duplicated // researcher url on database, // however there is no way to tell the controller that some of the // researcher urls were not // saved, so, if an error occurs, we need to reload researcher ids from // database and update // cached profile. A more efficient way to fix this might be used. if (hasErrors) { ResearcherUrls upToDateResearcherUrls = getUpToDateResearcherUrls(orcid, researcherUrls.getVisibility()); profile.getOrcidBio().setResearcherUrls(upToDateResearcherUrls); } redirectAttributes.addFlashAttribute("changesSaved", true); return manageBioView; }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
@RequestMapping(value = "/reset-password", method = RequestMethod.POST) public ModelAndView issuePasswordResetRequest(HttpServletRequest request, @ModelAttribute @Valid EmailAddressForm resetPasswordForm, BindingResult bindingResult) { String submittedEmail = resetPasswordForm.getUserEmailAddress(); ModelAndView mav = new ModelAndView("reset_password"); // if the email doesn't exist, or any other form errors.. don't bother // hitting db if (bindingResult.hasErrors()) { mav.addAllObjects(bindingResult.getModel()); return mav; }//from ww w . j a v a 2 s . c o m OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(submittedEmail, LoadOptions.BIO_ONLY); // if the email can't be found on the system, then add to errors if (profile == null) { String[] codes = { "orcid.frontend.reset.password.email_not_found" }; String[] args = { submittedEmail }; bindingResult.addError(new FieldError("userEmailAddress", "userEmailAddress", submittedEmail, false, codes, args, "Email not found")); mav.addAllObjects(bindingResult.getModel()); return mav; } else { if (profile.isDeactivated()) { mav.addObject("disabledAccount", true); return mav; } else { registrationManager.resetUserPassword(submittedEmail, profile); mav.addObject("passwordResetSuccessful", true); return mav; } } }
From source file:org.orcid.frontend.web.controllers.RegistrationController.java
@RequestMapping(value = "/resend-claim", method = RequestMethod.POST) public ModelAndView resendClaimEmail(HttpServletRequest request, @ModelAttribute @Valid EmailAddressForm emailAddressForm, BindingResult bindingResult) { String userEmailAddress = emailAddressForm.getUserEmailAddress(); ModelAndView mav = new ModelAndView("resend_claim"); // if the email doesn't exist, or any other form errors.. don't bother // hitting db if (bindingResult.hasErrors()) { mav.addAllObjects(bindingResult.getModel()); return mav; }//from w ww . j a va 2 s. co m OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(userEmailAddress); // if the email can't be found on the system, then add to errors if (profile == null) { String[] codes = { "orcid.frontend.reset.password.email_not_found" }; String[] args = { userEmailAddress }; bindingResult.addError(new FieldError("userEmailAddress", "userEmailAddress", userEmailAddress, false, codes, args, "Email not found")); mav.addAllObjects(bindingResult.getModel()); return mav; } else { if (profile.getOrcidHistory() != null && profile.getOrcidHistory().isClaimed()) { mav.addObject("alreadyClaimed", true); return mav; } else { notificationManager.sendApiRecordCreationEmail(userEmailAddress, profile); mav.addObject("claimResendSuccessful", true); return mav; } } }