List of usage examples for org.springframework.validation BindException hasErrors
@Override
public boolean hasErrors()
From source file:edu.wisc.my.portlets.bookmarks.web.BaseEntryFormController.java
/** * @see org.springframework.web.portlet.mvc.SimpleFormController#processFormSubmission(javax.portlet.ActionRequest, javax.portlet.ActionResponse, java.lang.Object, org.springframework.validation.BindException) */// w ww.j av a2s . c o m @Override protected void processFormSubmission(ActionRequest request, ActionResponse response, Object command, BindException errors) throws Exception { if (errors.hasErrors()) { final String action = request.getParameter("action"); final String idPath = request.getParameter("idPath"); final String folderPath = request.getParameter("folderPath"); response.setRenderParameter("action", action); response.setRenderParameter("idPath", idPath); response.setRenderParameter("folderPath", folderPath); } super.processFormSubmission(request, response, command, errors); }
From source file:org.jasig.cas.validation.UsernamePasswordCredentialsValidatorTests.java
private void commonTests(final UsernamePasswordCredentials c, int errorCountExpected) { final BindException b = new BindException(c, "credentials"); this.validator.validate(c, b); assertTrue(b.hasErrors()); assertEquals(b.getErrorCount(), errorCountExpected); }
From source file:org.jasig.cas.validation.UsernamePasswordCredentialsValidatorTests.java
public void testValidationPasses() { final UsernamePasswordCredentials c = TestUtils.getCredentialsWithSameUsernameAndPassword(); final BindException b = new BindException(c, "credentials"); this.validator.validate(c, b); assertFalse(b.hasErrors()); }
From source file:org.openmrs.module.restrictbyenctype.web.controller.EncTypeRestrictionFormController.java
@Override protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { if (errors.hasErrors()) { log.error("has Error : " + errors.getAllErrors()); return super.processFormSubmission(request, response, command, errors); }// www .j a v a 2s . c o m HttpSession httpSession = request.getSession(); RestrictByRoleService service = (RestrictByRoleService) Context.getService(RestrictByRoleService.class); EncTypeRestriction encTypeRestriction = (EncTypeRestriction) command; if (encTypeRestriction.getRoleRestrictionId() == null) { encTypeRestriction.setCreator(Context.getAuthenticatedUser()); encTypeRestriction.setDateCreated(new Date()); } if (encTypeRestriction.getVoided()) { encTypeRestriction.setVoidedBy(Context.getAuthenticatedUser()); encTypeRestriction.setDateVoided(new Date()); } if (encTypeRestriction.getRoleRestrictionId() == null) { service.createEncTypeRestriction(encTypeRestriction); } else { service.updateEncTypeRestriction(encTypeRestriction); } httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "encTypeRestriction.saved"); return new ModelAndView(new RedirectView(getSuccessView())); }
From source file:org.openmrs.module.kenyaemr.fragment.controller.developer.DeveloperUtilsFragmentController.java
/** * Validate patient records//from www . j a v a2 s . co m */ @AppAction(EmrConstants.APP_DEVELOPER) public List<SimpleObject> validatePatients(UiUtils ui) { List<SimpleObject> problems = new ArrayList<SimpleObject>(); for (Patient patient : Context.getPatientService().getAllPatients()) { BindException errors = new BindException(patient, ""); Context.getAdministrationService().validate(patient, errors); if (errors.hasErrors()) { SimpleObject problem = new SimpleObject(); problem.put("patient", ui.simplifyObject(patient)); problem.put("errors", uniqueErrorMessages(errors)); problem.put("cause", errors.getCause()); problems.add(problem); } } return problems; }
From source file:org.openmrs.web.controller.maintenance.ImplementationIdFormController.java
/** * Actions taken when the form is submitted * * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) *//*w w w . j av a2 s .co m*/ @Override protected ModelAndView onSubmit(HttpServletRequest req, HttpServletResponse response, Object object, BindException exceptions) throws Exception { ImplementationId implId = (ImplementationId) object; new ImplementationIdValidator().validate(implId, exceptions); if (exceptions.hasErrors()) { return showForm(req, response, exceptions); } try { Context.getAdministrationService().setImplementationId(implId); req.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "ImplementationId.validatedId"); } catch (APIException e) { log.warn("Unable to set implementation id", e); exceptions.reject(e.getMessage()); req.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage()); return showForm(req, response, exceptions); } return new ModelAndView(new RedirectView(getSuccessView())); }
From source file:org.inbio.modeling.web.controller.UpdateUserInfoController.java
@Override protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { ModelAndView model = new ModelAndView(); if (errors != null && errors.hasErrors()) model.addAllObjects(errors.getModel()); model.setViewName("admin/userDetails"); return model; }
From source file:org.inbio.modeling.web.controller.ExportController.java
@Override protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) { ModelAndView model = null;/*from w w w . ja va2s . c o m*/ if (errors != null && errors.hasErrors()) { model = new ModelAndView(); model.addAllObjects(errors.getModel()); } return null; }
From source file:org.openmrs.web.controller.concept.ConceptStopWordFormControllerTest.java
/** * @see {@link ConceptStopWordFormController#handleSubmission(HttpSession, ConceptStopWordFormBackingObject, org.springframework.validation.BindingResult) *//*from w w w . java2s . c o m*/ @Test @Verifies(value = "should return error message for an empty ConceptStopWord", method = "handleSubmission(HttpSession, ConceptStopWordFormBackingObject, BindingResult)") public void handleSubmission_shouldReturnErrorMessageForAnEmptyConceptStopWord() throws Exception { ConceptStopWordFormController controller = (ConceptStopWordFormController) applicationContext .getBean("conceptStopWordFormController"); HttpSession mockSession = new MockHttpSession(); ConceptStopWord conceptStopWord = new ConceptStopWord("", Locale.CANADA); mockSession.setAttribute("value", conceptStopWord.getValue()); BindException errors = new BindException(conceptStopWord, "value"); controller.handleSubmission(mockSession, conceptStopWord, errors); ObjectError objectError = (ObjectError) errors.getAllErrors().get(0); Assert.assertTrue(errors.hasErrors()); Assert.assertEquals(1, errors.getErrorCount()); Assert.assertEquals("ConceptStopWord.error.value.empty", objectError.getCode()); }
From source file:org.springmodules.validation.bean.conf.loader.xml.DefaultXmlBeanValidationConfigurationLoaderIntegrationTests.java
public void testShortCircuiteValidationEnabled() throws Exception { DefaultXmlBeanValidationConfigurationLoader loader = createLoader("TestBean3.vld.xml"); BeanValidator validator = new BeanValidator(loader); TestBean bean = new TestBean(); BindException errors = new BindException(bean, "bean"); validator.validate(bean, errors);/*from ww w . ja va2 s . c o m*/ assertTrue(errors.hasErrors()); assertTrue(errors.hasFieldErrors("name")); assertEquals(1, errors.getFieldErrorCount("name")); assertTrue(ArrayUtils.contains(errors.getFieldError("name").getCodes(), "TestBean.name[not.null]")); }