List of usage examples for org.springframework.validation BindException rejectValue
@Override
public void rejectValue(@Nullable String field, String errorCode, String defaultMessage)
From source file:org.toobsframework.exception.ValidationException.java
public ValidationException(Object bean, String name, String field, String errorCode, String defaultMessage) { BindException bindException = new BindException(bean, name); bindException.rejectValue(field, errorCode, defaultMessage); this.errors.add(bindException); }
From source file:org.remus.marketplace.controller.admin.NodeAdminController.java
@Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { Node node = (Node) command; if (StringUtils.isEmpty(node.getName())) { errors.rejectValue(Node.NAME, "empty.value", "Name must not be empty"); }//from www . ja va 2 s. co m if (StringUtils.isEmpty(node.getLicense())) { errors.rejectValue(Node.LICENSE, "empty.value", "License not be empty"); } if (node.getFoundationmember() == null || node.getFoundationmember() != 1 && node.getFoundationmember() != 0) { errors.rejectValue(Node.FOUNDATIONMEMBER, "wrong.value", "Please enter 0 or 1 as value"); } if (StringUtils.isEmpty(node.getShortdescription())) { errors.rejectValue(Node.SHORTDESCRIPTION, "empty.value", "Value must not be empty"); } super.onBindAndValidate(request, command, errors); }
From source file:edu.du.penrose.systems.fedoraApp.web.bus.GetFedorObjFormController.java
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { // request.getParameter( "objectPID") GetFedoraObjCmd getFOcmd = (GetFedoraObjCmd) command; Administrator administrator = (Administrator) request.getSession() .getAttribute("edu.du.penrose.systems.fedora.client.Administrator"); // query the server for field object fields try {/*from w w w . j av a2s . c om*/ GetFedorObjFormController.getFedoraObj(request, administrator.getAPIA(), getFOcmd.getObjectPID()); } catch (Exception e) { errors.rejectValue("objectPID", null, e.getMessage()); } return super.processFormSubmission(request, response, command, errors); }
From source file:org.sventon.web.ctrl.ConfigurationLoginController.java
@Override protected ModelAndView onSubmit(final HttpServletRequest request, final HttpServletResponse response, final Object command, final BindException errors) throws Exception { final ConfigLoginCommand configLoginCommand = (ConfigLoginCommand) command; final String passwordString = configLoginCommand.getUserPassword(); if (application.isValidConfigPassword(passwordString)) { logger.debug("Correct config password entered"); final HttpSession session = request.getSession(); session.setAttribute("isAdminLoggedIn", true); return super.onSubmit(configLoginCommand, errors); } else {/*from w w w . j a v a2s . c o m*/ logger.debug("Incorrect config password entered"); errors.rejectValue("userPassword", "illegal.config.password", "Illegal config password"); return super.showForm(request, response, errors); } }
From source file:it.geosolutions.geobatch.ui.mvc.FTPUserFormController.java
@Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { FtpUserDataBean givenData = (FtpUserDataBean) command; if (givenData == null) { errors.reject("error.nullpointer", "Null data received"); } else {//from w ww .j a v a 2 s. c o m /* VALIDATE ALL FIELDS */ if ((givenData.getUserName() == null) || (givenData.getUserName().trim().length() <= 0)) { errors.rejectValue("userName", "error.code", "Ftp User Name is mandatory."); } if ((givenData.getPassword() == null) || (givenData.getPassword().trim().length() <= 0)) { errors.rejectValue("password", "error.code", "Ftp User Password is mandatory."); } if ((givenData.getRepeatPassword() == null) || (givenData.getRepeatPassword().trim().length() <= 0)) { errors.rejectValue("repeatPassword", "error.code", "Ftp User Repeat Password is mandatory."); } if ((!givenData.getPassword().equals("")) && (!givenData.getRepeatPassword().equals(""))) { if (!givenData.getPassword().equals(givenData.getRepeatPassword())) { errors.rejectValue("password", "error.code", "The password must be the same."); } } if (request.getParameter("writePermission") == null) { givenData.setWritePermission(false); } if (!givenData.getDownloadRate().equals("")) { try { int downloadRate = Integer.parseInt(givenData.getDownloadRate()); if (downloadRate < 0) { errors.rejectValue("downloadRate", "error.code", "Ftp User Download Rate must be greater than 0."); } } catch (NumberFormatException e) { errors.rejectValue("downloadRate", "error.code", "Ftp User Download Rate must be an integer."); } } if (!givenData.getUploadRate().equals("")) { try { int uploadRate = Integer.parseInt(givenData.getUploadRate()); if (uploadRate < 0) { errors.rejectValue("uploadRate", "error.code", "Ftp User Upload Rate must be greater than 0."); } } catch (NumberFormatException e) { errors.rejectValue("uploadRate", "error.code", "Ftp User Upload Rate must be an integer."); } } } }
From source file:it.geosolutions.geobatch.ui.mvc.FTPConfigFormController.java
@Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { FtpConfigDataBean givenData = (FtpConfigDataBean) command; if (givenData == null) { errors.reject("error.nullpointer", "Null data received"); } else {//w w w.j a v a2 s.com /* VALIDATE ALL FIELDS */ if (request.getParameter("ssl") == null) { givenData.setSsl(false); } if (request.getParameter("autoStart") == null) { givenData.setAutoStart(false); } if (request.getParameter("anonEnabled") == null) { givenData.setAnonEnabled(false); } if (givenData.getMaxLogins() < 0) { errors.rejectValue("maxLogins", "error.code", "Ftp Max Logins must be greater than 0."); } if (givenData.getMaxLoginFailures() < 0) { errors.rejectValue("maxLoginFailures", "error.code", "Ftp Max Logins Failuers must be greater than 0."); } if (givenData.getLoginFailureDelay() < 0) { errors.rejectValue("loginFailureDelay", "error.code", "Ftp Login Failuers Delay must be greater than 0."); } } }
From source file:org.openmrs.web.controller.report.CohortReportFormController.java
/** * Handles parameters and rows, since Spring isn't good with lists * // w w w. j a v a 2s. c om * @see org.springframework.web.servlet.mvc.BaseCommandController#onBind(javax.servlet.http.HttpServletRequest, * java.lang.Object, org.springframework.validation.BindException) */ @Override protected void onBind(HttpServletRequest request, Object commandObj, BindException errors) throws Exception { CommandObject command = (CommandObject) commandObj; // parameters String[] paramNames = request.getParameterValues("parameterName"); String[] paramLabels = request.getParameterValues("parameterLabel"); String[] paramClasses = request.getParameterValues("parameterClass"); List<Parameter> params = new ArrayList<Parameter>(); if (paramNames != null) { for (int i = 0; i < paramNames.length; ++i) { if (StringUtils.hasText(paramNames[i]) || StringUtils.hasText(paramLabels[i]) || StringUtils.hasText(paramClasses[i])) { try { Class<?> clz = null; if (StringUtils.hasText(paramClasses[i])) clz = Class.forName(paramClasses[i]); Parameter p = new Parameter(paramNames[i], paramLabels[i], clz, null); params.add(p); } catch (Exception ex) { errors.rejectValue("parameters", null, "Parameter error: " + ex.toString()); } } } } command.setParameters(params); // rows String[] rowNames = request.getParameterValues("rowName"); String[] rowDescriptions = request.getParameterValues("rowDescription"); String[] rowQueries = request.getParameterValues("rowQuery"); List<CohortReportRow> rows = new ArrayList<CohortReportRow>(); if (rowNames != null) { for (int i = 0; i < rowNames.length; ++i) { try { CohortReportRow row = new CohortReportRow(); row.setName(rowNames[i]); row.setDescription(rowDescriptions[i]); row.setQuery(rowQueries[i]); rows.add(row); } catch (Exception ex) { errors.rejectValue("rows", null, "Row error: " + ex.toString()); } } } command.setRows(rows); }
From source file:gov.nih.nci.cabig.caaers.web.admin.CreateINDController.java
public void validate(INDCommand command, BindException errors) { BeanWrapper commandBean = new BeanWrapperImpl(command); for (InputFieldGroup fieldGroup : fieldMap.values()) { for (InputField field : fieldGroup.getFields()) { field.validate(commandBean, errors); }//from w ww .j a v a2 s. c om } // check if the strINDNumber is a numeric value if (!StringUtils.isNumeric((String) commandBean.getPropertyValue("strINDNumber"))) { errors.rejectValue("strINDNumber", "ADM_IND_001", "IND# must be numeric"); } }
From source file:gov.nih.nci.cabig.caaers.web.ae.CreateReportingPeriodController.java
/** * Validates the reporting period create/edit business rules. * 1. Should have all the field level validations met * 2. Should be associated to Treatment assignment * 3. Only one basline reporting period is allowed * 4. Validation on Datest @see {@link CreateReportingPeriodController#validateRepPeriodDates(AdverseEventReportingPeriod, List, Errors)} *//*from w w w . j a v a2 s .co m*/ @Override protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { super.onBindAndValidate(request, command, errors); BeanWrapper commandBean = new BeanWrapperImpl(command); Map<String, InputFieldGroup> fieldGroups = createFieldGroups(command); //do all field level validation for (InputFieldGroup fieldGroup : fieldGroups.values()) { for (InputField field : fieldGroup.getFields()) { field.validate(commandBean, errors); } } ReportingPeriodCommand rpCommand = (ReportingPeriodCommand) command; AdverseEventReportingPeriod rPeriod = rpCommand.getReportingPeriod(); List<AdverseEventReportingPeriod> rPeriodList = rpCommand.getAssignment().getActiveReportingPeriods(); //check the treatment assignment. if (isFieldRequired("reportingPeriod.treatmentAssignment")) { if (rPeriod.getTreatmentAssignment() == null || rPeriod.getTreatmentAssignment().getId() == null) { if (StringUtils.isEmpty(rPeriod.getTreatmentAssignmentDescription())) { errors.reject("CRP_001", "Treatment assignment description is missing"); return; } } else { if (rPeriod.getTreatmentAssignment().isRetired()) { errors.reject("CRP_009", "Treatment assignment should be active"); return; } } } // Check for duplicate baseline Reporting Periods. if (rPeriod.getEpoch() != null && rPeriod.getEpoch().getName().equals("Baseline")) { for (AdverseEventReportingPeriod aerp : rPeriodList) { if (!aerp.getId().equals(rPeriod.getId()) && aerp.getEpoch() != null && aerp.getEpoch().getName().equals("Baseline")) { InputField epochField = fieldGroups.get(REPORTINGPERIOD_FIELD_GROUP).getFields().get(3); errors.rejectValue(epochField.getPropertyName(), "CRP_002", "A Baseline treatment type already exists"); return; } } } //validate the date related logic. if (!errors.hasErrors()) validateRepPeriodDates(rpCommand.getReportingPeriod(), rpCommand.getAssignment().getActiveReportingPeriods(), rpCommand.getAssignment().getStartDateOfFirstCourse(), errors); }
From source file:gov.nih.nci.cabig.caaers.web.rule.notification.CreateConfigPropertyController.java
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException e) throws Exception { super.onBindAndValidate(request, command, e); ReportTypeCommand cmd = (ReportTypeCommand) command; BeanWrapper cmdWrapper = new BeanWrapperImpl(cmd); for (InputField field : createFieldGroups(cmd).get(REPORTTYPE_FIELD_GROUP).getFields()) { field.validate(cmdWrapper, e);// w w w . j av a 2 s . c o m } List<ConfigProperty> list = cpDao.getByType(cmd.getConfigPropertyType()); for (ConfigProperty cp : list) { if (cp.getCode().equals(cmd.getCode())) { e.rejectValue("code", "CP_011", "Duplicate report group code"); } if (cp.getName().equals(cmd.getName())) { e.rejectValue("name", "CP_012", "Duplicate report group name"); } } }