List of usage examples for org.springframework.validation BindingResult rejectValue
void rejectValue(@Nullable String field, String errorCode);
From source file:org.egov.eis.web.controller.masters.employee.ViewAndUpdateEmployeController.java
@RequestMapping(value = "/update/{code}", method = RequestMethod.POST) public String update(@Valid @ModelAttribute final Employee employee, final BindingResult errors, final RedirectAttributes redirectAttrs, final Model model, @RequestParam final MultipartFile file, @RequestParam final String removedJurisdictionIds, @RequestParam final String removedassignIds) { final Boolean codeExists = employeeService.validateEmployeeCode(employee); if (codeExists) errors.rejectValue("code", "Unique.employee.code"); try {/*from w w w. j a va 2 s .c o m*/ if (!file.isEmpty()) employee.setSignature(file.getBytes()); } catch (final IOException e) { LOGGER.error("Error in loading Employee Signature" + e.getMessage(), e); } jurisdictionService.removeDeletedJurisdictions(employee, removedJurisdictionIds); final String positionName = employeeService.validatePosition(employee, removedassignIds); if (StringUtils.isNotBlank(positionName)) { setDropDownValues(model); final String fieldError = messageSource.getMessage("position.exists.workflow", new String[] { positionName }, null); model.addAttribute("error", fieldError); return EMPLOYEEFORM; } if (!employeeService.primaryAssignmentExists(employee) && employee.isActive()) errors.rejectValue("assignments", "primary.assignment"); if (employeeService.primaryAssignExistsForSamePeriod(employee)) errors.rejectValue("assignments", "primary.assignment.daterange"); if (errors.hasErrors()) { setDropDownValues(model); model.addAttribute("mode", "update"); return EMPLOYEEFORM; } String image = null; if (null != employee.getSignature()) image = Base64.encodeBytes(employee.getSignature()); model.addAttribute(IMAGE, image); employeeService.update(employee); redirectAttrs.addFlashAttribute("employee", employee); model.addAttribute("message", "Employee updated successfully"); return EMPLOYEESUCCESS; }
From source file:org.egov.pgr.web.controller.complaint.citizen.CitizenComplaintRegistrationController.java
@RequestMapping(value = "register", method = POST) public String registerComplaint(@Valid @ModelAttribute Complaint complaint, BindingResult resultBinder, RedirectAttributes redirectAttributes, @RequestParam("files") MultipartFile[] files, Model model) { if (complaint.getCrossHierarchyId() != null) { CrossHierarchy crosshierarchy = crossHierarchyService.findById(complaint.getCrossHierarchyId()); complaint.setLocation(crosshierarchy.getParent()); complaint.setChildLocation(crosshierarchy.getChild()); }//from ww w. j a va 2 s . com if (complaint.getLocation() == null && (complaint.getLat() == 0 || complaint.getLng() == 0)) resultBinder.rejectValue(LOCATION, "location.required"); if (resultBinder.hasErrors()) { if (complaint.getCrossHierarchyId() != null) model.addAttribute("crossHierarchyLocation", complaint.getChildLocation().getName() + " - " + complaint.getLocation().getName()); return CITIZEN_COMPLAINT_REGISTRATION_FORM; } try { complaint.setSupportDocs(fileStoreUtils.addToFileStore(files, MODULE_NAME, true)); complaintService.createComplaint(complaint); } catch (ValidationException e) { resultBinder.rejectValue(LOCATION, e.getMessage()); return CITIZEN_COMPLAINT_REGISTRATION_FORM; } redirectAttributes.addFlashAttribute("complaint", complaint); return "redirect:/complaint/reg-success/" + complaint.getCrn(); }
From source file:org.egov.pgr.web.controller.complaint.citizen.CitizenComplaintRegistrationController.java
@RequestMapping(value = "anonymous/register", method = POST) public String registerComplaintAnonymous(@Valid @ModelAttribute Complaint complaint, BindingResult resultBinder, RedirectAttributes redirectAttributes, HttpServletRequest request, @RequestParam("files") MultipartFile[] files, Model model) { if (!captchaUtils.captchaIsValid(request)) resultBinder.reject("captcha.not.valid"); if (isBlank(complaint.getComplainant().getEmail()) && isBlank(complaint.getComplainant().getMobile())) resultBinder.rejectValue("complainant.email", "email.or.mobile.ismandatory"); if (isBlank(complaint.getComplainant().getName())) resultBinder.rejectValue("complainant.name", "complainant.name.ismandatory"); if (complaint.getCrossHierarchyId() != null) { CrossHierarchy crosshierarchy = crossHierarchyService.findById(complaint.getCrossHierarchyId()); complaint.setLocation(crosshierarchy.getParent()); complaint.setChildLocation(crosshierarchy.getChild()); }/* ww w . j ava2 s . co m*/ if (complaint.getLocation() == null && (complaint.getLat() == 0 || complaint.getLng() == 0)) resultBinder.rejectValue(LOCATION, "location.required"); if (resultBinder.hasErrors()) { if (null != complaint.getCrossHierarchyId()) model.addAttribute("crossHierarchyLocation", complaint.getChildLocation().getName() + " - " + complaint.getLocation().getName()); return ANONYMOUS_COMPLAINT_REGISTRATION_FORM; } try { complaint.setSupportDocs(fileStoreUtils.addToFileStore(files, MODULE_NAME, true)); complaintService.createComplaint(complaint); } catch (ValidationException e) { resultBinder.rejectValue(LOCATION, e.getMessage()); return ANONYMOUS_COMPLAINT_REGISTRATION_FORM; } redirectAttributes.addFlashAttribute("complaint", complaint); return "redirect:/complaint/reg-success/" + complaint.getCrn(); }
From source file:org.egov.pgr.web.controller.complaint.officials.OfficialsComplaintRegistrationController.java
@RequestMapping(value = "register", method = POST) public String registerComplaint(@Valid @ModelAttribute final Complaint complaint, final BindingResult resultBinder, final RedirectAttributes redirectAttributes, @RequestParam("files") final MultipartFile[] files, final Model model) { if (null != complaint.getCrossHierarchyId()) { final CrossHierarchy crosshierarchy = crossHierarchyService.findById(complaint.getCrossHierarchyId()); complaint.setLocation(crosshierarchy.getParent()); complaint.setChildLocation(crosshierarchy.getChild()); }//from w ww .j a v a 2 s. c om if (complaint.getLocation() == null && (complaint.getLat() == 0 || complaint.getLng() == 0)) resultBinder.rejectValue("location", "location.required"); if (isBlank(complaint.getComplainant().getMobile())) resultBinder.rejectValue("complainant.mobile", "mobile.ismandatory"); if (resultBinder.hasErrors()) { if (null != complaint.getCrossHierarchyId()) model.addAttribute("crossHierarchyLocation", complaint.getChildLocation().getName() + " - " + complaint.getLocation().getName()); return OFFICIALS_COMPLAINT_REGISTRATION_FORM; } try { complaint.setSupportDocs(fileStoreUtils.addToFileStore(files, PGRConstants.MODULE_NAME, true)); complaintService.createComplaint(complaint); } catch (final ValidationException e) { resultBinder.rejectValue("location", e.getMessage()); return OFFICIALS_COMPLAINT_REGISTRATION_FORM; } redirectAttributes.addFlashAttribute("complaint", complaint); return "redirect:/complaint/reg-success/" + complaint.getCrn(); }
From source file:org.egov.pgr.web.controller.complaint.thirdparty.GrievanceRegistrationController.java
@PostMapping("register-grievance") public String registerComplaint(@Valid @ModelAttribute final Complaint complaint, final BindingResult resultBinder, final RedirectAttributes redirectAttributes, @RequestParam("files") final MultipartFile[] files, final Model model) { if (null != complaint.getCrossHierarchyId()) { final CrossHierarchy crosshierarchy = crossHierarchyService.findById(complaint.getCrossHierarchyId()); complaint.setLocation(crosshierarchy.getParent()); complaint.setChildLocation(crosshierarchy.getChild()); }/*w w w. ja va2 s . c o m*/ if (complaint.getLocation() == null && (complaint.getLat() == 0 || complaint.getLng() == 0)) resultBinder.rejectValue("location", "location.required"); if (isBlank(complaint.getComplainant().getMobile())) resultBinder.rejectValue("complainant.mobile", "mobile.ismandatory"); if (resultBinder.hasErrors()) { if (null != complaint.getCrossHierarchyId()) model.addAttribute("crossHierarchyLocation", complaint.getChildLocation().getName() + " - " + complaint.getLocation().getName()); return GRIEVANCE_REGISTRATION_FORM; } try { complaint.setSupportDocs(fileStoreUtils.addToFileStore(files, PGRConstants.MODULE_NAME, true)); complaintService.createComplaint(complaint); } catch (final ValidationException e) { resultBinder.rejectValue("location", e.getMessage()); return GRIEVANCE_REGISTRATION_FORM; } redirectAttributes.addFlashAttribute("complaint", complaint); return "redirect:/complaint/reg-success/" + complaint.getCrn(); }
From source file:org.egov.portal.web.controller.citizen.CitizenRegistrationController.java
@RequestMapping(method = POST) public String registerCitizen(@Valid @ModelAttribute Citizen citizen, BindingResult errors, HttpServletRequest request, RedirectAttributes redirectAttrib) { if (!validatorUtils.isValidPassword(citizen.getPassword())) errors.rejectValue("password", "error.pwd.invalid"); else if (!StringUtils.equals(citizen.getPassword(), request.getParameter("con-password"))) errors.rejectValue("password", "error.pwd.mismatch"); if (!citizenService.isValidOTP(citizen.getActivationCode(), citizen.getMobileNumber())) errors.rejectValue("activationCode", "error.otp.verification.failed"); if (errors.hasErrors()) return "signup"; citizenService.create(citizen);/*from w w w.j av a 2s. c om*/ redirectAttrib.addFlashAttribute("mobileNo", citizen.getMobileNumber()); redirectAttrib.addFlashAttribute("message", "msg.reg.success"); return "redirect:signup"; }
From source file:org.egov.ptis.web.controller.transactions.deactivation.PropertyDeactivationController.java
@RequestMapping(value = "/search/{assessmentNo}", method = RequestMethod.POST) public String deactivationSearchForm(@ModelAttribute final PropertyDeactivation propertyDeactivation, final Model model, final BindingResult resultBinder, @PathVariable("assessmentNo") final String assessmentNo, final HttpServletRequest request, final Errors errors) { List<String> deactivationReasons = propertyDeactivationService.getDeactivationReasons(); List<DocumentType> documentTypes; boolean isPropChildUnderWF; boolean hasActiveWC; model.addAttribute(BASIC_PROPERTY, propertyDeactivation.getBasicproperty()); model.addAttribute("reasonMaster", propertyDeactivation.getReasonMaster()); model.addAttribute(ORIGINAL_PROPERTY, propertyDeactivation.getOriginalAssessment()); model.addAttribute(DEACTIVATE_REASONS, deactivationReasons); BasicProperty basicProperty = basicPropertyDAO.getBasicPropertyByPropertyID(assessmentNo); BasicProperty orgBasicProp = basicPropertyDAO .getBasicPropertyByPropertyID(propertyDeactivation.getOriginalAssessment()); if (basicProperty == null) { resultBinder.rejectValue(BASIC_PROPERTY, NO_PROP_ERROR); return DEACT_FORM; } else {//from www .ja v a 2 s . c om isPropChildUnderWF = propertyTaxUtil.checkForParentUsedInBifurcation(basicProperty.getUpicNo()); if (basicProperty.isUnderWorkflow() || isPropChildUnderWF) { resultBinder.rejectValue(BASIC_PROPERTY, "error.prop.under.wf"); return DEACT_FORM; } else if (!UNTRACED_PROPERTY.equalsIgnoreCase(propertyDeactivation.getReasonMaster())) { if (orgBasicProp == null || basicProperty.getUpicNo().equals(orgBasicProp.getUpicNo())) { resultBinder.rejectValue(ORIGINAL_PROPERTY, NO_PROP_ERROR); return DEACT_FORM; } else { Map<String, String> orgPropDetails = propertyDeactivationService .getPropertyDetails(orgBasicProp); List<Map<String, Object>> orgPropWCDetails = propertyService .getWCDetails(orgBasicProp.getUpicNo(), request); model.addAttribute("orgPropDetails", orgPropDetails); model.addAttribute("orgPropWCDetails", orgPropWCDetails); } } } Map<String, String> propDetails = propertyDeactivationService.getPropertyDetails(basicProperty); List<Map<String, Object>> wcDetails = propertyService.getWCDetails(basicProperty.getUpicNo(), request); hasActiveWC = propertyDeactivationService.checkActiveWC(wcDetails); model.addAttribute("propDetails", propDetails); model.addAttribute("wcDetails", wcDetails); model.addAttribute("hasActiveWC", hasActiveWC); documentTypes = propertyService.getDocumentTypesForTransactionType(TransactionType.DEACTIVATE); model.addAttribute("documentTypes", documentTypes); return DEACT_FORM; }
From source file:org.egov.ptis.web.controller.transactions.deactivation.PropertyDeactivationController.java
@RequestMapping(value = "/update/{assessmentNo}", method = RequestMethod.POST) public String deactivationFormSubmit(@ModelAttribute final PropertyDeactivation propertyDeactivation, final BindingResult resultBinder, final RedirectAttributes redirectAttrs, final Model model, @PathVariable("assessmentNo") final String assessmentNo) { BasicProperty basicProperty = basicPropertyDAO.getBasicPropertyByPropertyID(assessmentNo); final List<Document> documents = new ArrayList<>(); if (basicProperty == null) { resultBinder.rejectValue(BASIC_PROPERTY, NO_PROP_ERROR); return DEACT_FORM; } else if (basicProperty.isUnderWorkflow()) { resultBinder.rejectValue(BASIC_PROPERTY, "error.prop.under.wf"); return DEACT_FORM; } else if (propertyDeactivation.getOriginalAssessment() == null && !UNTRACED_PROPERTY.equalsIgnoreCase(propertyDeactivation.getReasonMaster())) { resultBinder.rejectValue(ORIGINAL_PROPERTY, NO_PROP_ERROR); return DEACT_FORM; } else {// ww w . j a v a 2 s . co m documents.addAll(propertyDeactivation.getDocuments()); propertyDeactivation.getDocuments().clear(); propertyDeactivation.setDocuments(documents); processAndStoreApplicationDocuments(propertyDeactivation); PropertyStatusValues propStatusValues = propertyService.createPropStatVal(basicProperty, PropertyTaxConstants.PROP_DEACT_RSN, null, null, null, null, null); propertyDeactivation.setBasicproperty(basicProperty.getId()); propertyDeactivationService.save(propertyDeactivation); basicProperty.setActive(false); basicProperty.setModifiedDate(new Date()); basicProperty.addPropertyStatusValues(propStatusValues); basicPropertyService.persist(basicProperty); model.addAttribute("message", "deactivate.ack.msg"); model.addAttribute("assessmentNo", assessmentNo); return "deactivation-success"; } }
From source file:org.egov.ptis.web.controller.transactions.editCollection.EditCollectionController.java
private BindingResult validate(final DemandDetailBeansForm demandDetailBeansForm, final BindingResult errors) { Boolean editingCollection = Boolean.FALSE; int i = 0;//w ww . ja v a 2 s .c om BigDecimal totalRevisedCollection = BigDecimal.ZERO; BigDecimal totalActualCollection = BigDecimal.ZERO; for (final DemandDetail dd : demandDetailBeansForm.getDemandDetailBeans()) { dd.setInstallment(installmentDao.findById(dd.getInstallment().getId(), false)); if (dd.getReasonMaster().equals(DEMANDRSN_STR_PENALTY_FINES)) { if (dd.getRevisedAmount() != null && dd.getRevisedCollection() != null) { if (dd.getRevisedCollection().compareTo(dd.getRevisedAmount()) > 0) { errors.rejectValue("demandDetailBeans[" + i + "].revisedAmount", "revised.collection.greater.than.reviseddemand"); errors.rejectValue(String.format(REVISED_COLLECTION_FIELD, i), "revised.demand.less.than.revisedcollection"); } else if (dd.getRevisedCollection().compareTo(dd.getRevisedAmount()) < 0) errors.rejectValue(String.format(REVISED_COLLECTION_FIELD, i), ERROR_PENALTY_NOT_COLLECTED); editingCollection = Boolean.TRUE; totalRevisedCollection = totalRevisedCollection.add(dd.getRevisedCollection()); totalActualCollection = totalActualCollection.add(dd.getActualCollection()); } else if (dd.getRevisedAmount() != null) { if (dd.getActualCollection().compareTo(dd.getRevisedAmount()) > 0) errors.rejectValue("demandDetailBeans[" + i + "].revisedAmount", "actual.collection.greater.than.reviseddemand"); else if (dd.getRevisedCollection() != null && dd.getRevisedCollection().compareTo(dd.getRevisedAmount()) < 0 || dd.getActualCollection().compareTo(dd.getRevisedAmount()) < 0) errors.rejectValue(String.format(REVISED_COLLECTION_FIELD, i), ERROR_PENALTY_NOT_COLLECTED); editingCollection = Boolean.TRUE; } else if (dd.getRevisedCollection() != null) { if (dd.getRevisedCollection().compareTo(dd.getActualAmount()) > 0) errors.rejectValue(String.format(REVISED_COLLECTION_FIELD, i), "revised.collection.greater.than.actualdemand"); else if (dd.getRevisedCollection().compareTo(dd.getActualAmount()) < 0) errors.rejectValue(String.format(REVISED_COLLECTION_FIELD, i), ERROR_PENALTY_NOT_COLLECTED); editingCollection = Boolean.TRUE; totalRevisedCollection = totalRevisedCollection.add(dd.getRevisedCollection()); totalActualCollection = totalActualCollection.add(dd.getActualCollection()); } } else if (null != dd.getRevisedCollection() && dd.getRevisedCollection().compareTo(BigDecimal.ZERO) != 0) { if (dd.getRevisedCollection().compareTo(dd.getActualAmount()) > 0) errors.rejectValue(String.format(REVISED_COLLECTION_FIELD, i), "revised.collection.greater.than.actualdemand"); editingCollection = Boolean.TRUE; totalRevisedCollection = totalRevisedCollection.add(dd.getRevisedCollection()); totalActualCollection = totalActualCollection.add(dd.getActualCollection()); } i++; } if (editingCollection) { if (StringUtils.isBlank(demandDetailBeansForm.getPropertyReceipt().getRemarks())) errors.rejectValue(PROPERTY_RECEIPT_REMARKS, MANDATORY_MESSAGE); if (StringUtils.isBlank(demandDetailBeansForm.getPropertyReceipt().getReceiptNumber())) errors.rejectValue("propertyReceipt.receiptNumber", MANDATORY_MESSAGE); if (demandDetailBeansForm.getPropertyReceipt().getReceiptDate() == null) errors.rejectValue("propertyReceipt.receiptDate", MANDATORY_MESSAGE); if (demandDetailBeansForm.getPropertyReceipt().getReceiptAmount() == null) errors.rejectValue("propertyReceipt.receiptAmount", MANDATORY_MESSAGE); else if (totalRevisedCollection .compareTo(demandDetailBeansForm.getPropertyReceipt().getReceiptAmount()) != 0) errors.rejectValue(PROPERTY_RECEIPT_REMARKS, "error.receipt.amount"); } else if (!editingCollection) errors.rejectValue(PROPERTY_RECEIPT_REMARKS, "error.collection.notmodified"); return errors; }
From source file:org.egov.ptis.web.controller.vacancyremission.VacanyRemissionController.java
private void validateDates(final VacancyRemission vacancyRemission, final BindingResult errors) { final int noOfMonths = DateUtils.noOfMonthsBetween(vacancyRemission.getVacancyFromDate(), new DateTime(vacancyRemission.getVacancyToDate()).plusDays(1).toDate()); if (noOfMonths < 6) errors.rejectValue("vacancyToDate", "vacancyToDate.incorrect"); }