List of usage examples for org.springframework.validation BindingResult reject
void reject(String errorCode);
From source file:org.openmrs.module.cohort.web.controller.AddVisitController.java
@RequestMapping(value = "/module/cohort/addvisit.form", method = RequestMethod.POST) public void onSubmit(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "startDate") String startDate, @RequestParam(required = false, value = "endDate") String endDate, @ModelAttribute("cohortvisit") CohortVisit cvisit, BindingResult errors) { CohortService departmentService = Context.getService(CohortService.class); if (!Context.isAuthenticated()) { errors.reject("Required"); }/*from ww w . jav a 2 s . com*/ VisitService enctype = Context.getVisitService(); List<VisitType> enctypes = enctype.getAllVisitTypes(); VisitType e = new VisitType(); Location l = new Location(); LocationService service = Context.getLocationService(); List<String> cohortnames = new ArrayList<String>(); List<String> etype = new ArrayList<String>(); CohortService cservice = Context.getService(CohortService.class); CohortM c1 = new CohortM(); List<CohortM> list1 = cservice.findCohorts(); for (int i = 0; i < list1.size(); i++) { CohortM c = list1.get(i); cohortnames.add(c.getName()); } for (int k = 0; k < enctypes.size(); k++) { VisitType ec = enctypes.get(k); etype.add(e.getName()); } List<Location> formats = service.getAllLocations(); model.addAttribute("formats1", cohortnames); model.addAttribute("locations", formats); model.addAttribute("enctypes", etype); String visittype = request.getParameter("visittype"); String location = request.getParameter("location"); String cohort = request.getParameter("names"); if (startDate == "" && endDate == "") { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Values cannot be null"); } else { List<CohortM> cohort2 = cservice.findCohorts(cohort); for (int i = 0; i < cohort2.size(); i++) { c1 = cohort2.get(i); } List<VisitType> visittypes1 = enctype.getVisitTypes(visittype); for (int i = 0; i < visittypes1.size(); i++) { e = visittypes1.get(i); } List<Location> loc = service.getLocations(location); for (int j = 0; j < loc.size(); j++) { l = loc.get(j); } cvisit.setCohort(c1); cvisit.setVisitType(e); cvisit.setLocation(l); cservice.saveCohortVisit(cvisit); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); } }
From source file:org.openmrs.module.cohort.web.controller.AddObs.java
@RequestMapping(value = "/module/cohort/addobs.form", method = RequestMethod.POST) public ModelAndView onSubmit(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "obsDateTime") String date, @ModelAttribute("cohortobs") CohortObs cobs, BindingResult errors) { CohortService departmentService = Context.getService(CohortService.class); if (!Context.isAuthenticated()) { errors.reject("Required"); }//from www.j a v a 2 s .c om Location l = new Location(); Concept co = new Concept(); LocationService service = Context.getLocationService(); ConceptService cs = Context.getConceptService(); List<Concept> concept = cs.getAllConcepts(); List<String> cohortnames = new ArrayList<String>(); CohortService cservice = Context.getService(CohortService.class); CohortM c1 = new CohortM(); CohortEncounter ce = new CohortEncounter(); List<CohortM> list1 = cservice.findCohorts(); for (int d = 0; d < list1.size(); d++) { CohortM c = list1.get(d); cohortnames.add(c.getName()); } List<Integer> etype = new ArrayList<Integer>(); List<CohortEncounter> enctypes = cservice.findCohortEncounters(); for (int a = 0; a < enctypes.size(); a++) { CohortEncounter e = enctypes.get(a); etype.add(e.getId()); } List<Location> formats = service.getAllLocations(); model.addAttribute("concepts", concept); model.addAttribute("locations", formats); model.addAttribute("encids", etype); String encounterid = request.getParameter("encid"); Integer id = Integer.parseInt(encounterid); String location = request.getParameter("location"); String cohort = request.getParameter("names"); String concept1 = request.getParameter("concept"); if (date == "") { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Values cannot be null"); } else { List<CohortM> cohort2 = cservice.findCohorts(cohort); for (int i = 0; i < cohort2.size(); i++) { c1 = cohort2.get(i); } List<CohortEncounter> enctypes1 = cservice.findCohortEnc(id); for (int g = 0; g < enctypes1.size(); g++) { ce = enctypes1.get(g); } List<Location> loc = service.getLocations(location); for (int j = 0; j < loc.size(); j++) { l = loc.get(j); } List<Concept> con = cs.getConceptsByName(concept1); for (int x = 0; x < con.size(); x++) { co = con.get(x); } cobs.setCohort(c1); //cobs.setVoided(false); //cobs.setConcept(co); cobs.setEncounterId(ce); cobs.setLocation(l); departmentService.saveCohortObs(cobs); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "insertion success"); } return null; }
From source file:org.sloth.web.account.LoginController.java
/** * Handles the {@code POST} request. Validates the login form and authorizes * the {@code HttpSession}.//from ww w .ja v a 2 s. c om */ @RequestMapping(method = RequestMethod.POST) public String login(@ModelAttribute(LOGIN_ATTRIBUTE) Login login, BindingResult result, SessionStatus status, HttpSession session) { if (isAuth(session)) { return "redirect:/"; } else { this.loginValidator.validate(login, result); if (result.hasErrors()) { return VIEW; } else { User u = this.userService.login(login.getMail(), login.getPassword()); if (u == null) { result.reject("field.login.invalid"); return VIEW; } else { logger.debug("Got valid user. Setting Session-Attribute."); auth(session, u); status.setComplete(); return "redirect:/"; } } } }
From source file:com.devnexus.ting.web.controller.admin.UserChangePasswordController.java
@RequestMapping(value = "/s/admin/change-password", method = RequestMethod.POST) public String changePassword(@Valid UserChangePasswordForm userChangePasswordForm, BindingResult result, RedirectAttributes redirectAttributes, HttpServletRequest request) { if (request.getParameter("cancel") != null) { return "redirect:/s/admin/index"; }// w ww .jav a 2s . c o m if (result.hasErrors()) { return "/admin/user-change-password"; } if (userChangePasswordForm.getPassword1().equals(userChangePasswordForm.getPassword2())) { userService.changePassword(userChangePasswordForm.getPassword1()); } else { result.reject("Passwords did not match."); return "/admin/user-change-password"; } redirectAttributes.addFlashAttribute("successMessage", "The password was changed successfully."); return "redirect:/s/admin/index"; }
From source file:fi.koku.kks.controller.CreateCollectionController.java
@ActionMapping(params = "action=createNewVersion") public void createVersion(PortletSession session, @ModelAttribute(value = "child") Person child, @RequestParam String id, Version version, BindingResult result, ActionResponse response, SessionStatus sessionStatus) {/*from ww w.j av a 2s. c om*/ version.validate(version, result); if (!result.hasErrors()) { LOG.debug("create new version"); String collection = kksService.createKksCollectionVersion(version.getName(), id, child.getPic(), version.isClear(), Utils.getPicFromSession(session)); if (collection == null) { result.reject("collection.create.failed"); response.setRenderParameter("action", "showCollection"); response.setRenderParameter("pic", child.getPic()); response.setRenderParameter("collection", id); } else { version.setClear(false); response.setRenderParameter("action", "showCollection"); response.setRenderParameter("pic", child.getPic()); response.setRenderParameter("collection", collection); sessionStatus.setComplete(); } } else { response.setRenderParameter("action", "showCollection"); response.setRenderParameter("pic", child.getPic()); response.setRenderParameter("collection", id); } }
From source file:gallery.web.validator.wallpaper.comment.WallpaperCommentValidator.java
@Override public BindingResult bindAndValidate(Object command, HttpServletRequest request) { BindingResult res = super.bindAndValidate(command, request); if (!res.hasErrors()) { WallpaperComment p = (WallpaperComment) command; //checking if there is such wallpaper if (wallpaperService.getRowCount("id", p.getId_photo()) == 1) { p.setCreationTime(new Timestamp(System.currentTimeMillis())); //setting user p.setUser(security.Utils.getCurrentUser(request)); } else {/*from ww w .j a v a 2s . c o m*/ common.CommonAttributes.addErrorMessage("not_exists.wallpaper", request); res.reject("not_exists.wallpaper"); } } return res; }
From source file:cn.loveapple.service.controller.member.action.MemberController.java
/** * ???????// www . ja v a 2s . c o m * * @param form * @param result * @return */ @RequestMapping(value = "auth", method = RequestMethod.POST) public String auth(@Valid MemberAuthForm form, BindingResult result, HttpSession session) { if (result.hasErrors()) { return "member/index"; } LoveappleMemberModel member = memberCoreService.authenticateLoveappleMember(form.getMail(), form.getPassword()); if (member == null) { result.reject("loveappleErrors.auth"); return "member/index"; } session.setAttribute(LOVEAPPLE_MEMBER, member); Object refererUrl = session.getAttribute(REFERER_INNER_URL); if (log.isDebugEnabled()) { log.debug("auth will redirect? [" + refererUrl + "]"); } if (refererUrl != null) { session.removeAttribute(REFERER_INNER_URL); return "redirect:" + refererUrl; } return "redirect:/member/core/info/" + member.getKey().getId(); }
From source file:org.parancoe.basicWebApp.controllers.PeopleEditController.java
@RequestMapping protected String update(@ModelAttribute("person") @Valid Person person, BindingResult result, SessionStatus status) {/*from w w w . ja va 2 s. c o m*/ try { if (result.hasErrors()) { logger.error("Result of validation has errors (" + result.getAllErrors().toString() + ")"); return "people/edit"; } else { personDao.store(person); logger.info("Stored the person (" + person + ")"); status.setComplete(); return "redirect:list.html"; } } catch (Exception e) { logger.error("Problema salvando Utente " + person, e); result.reject("error.generic"); return "people/edit"; } }