List of usage examples for org.springframework.validation BindingResult hasFieldErrors
boolean hasFieldErrors(String field);
From source file:org.jtalks.jcommune.web.controller.PostController.java
/** * Prepare ModelAndView for showing preview * * @return prepared ModelAndView for preview *//*from ww w . j av a 2 s. co m*/ private ModelAndView getPreviewModelAndView(BindingResult result) { return new ModelAndView("ajax/postPreview").addObject("isInvalid", result.hasFieldErrors("bodyText")) .addObject("errors", result.getFieldErrors("bodyText")); }
From source file:org.opens.kbaccess.controller.TestcaseController.java
@RequestMapping(value = "add-finalize", method = RequestMethod.POST) public String finalizeAddHandler(@ModelAttribute("newTestcaseCommand") NewTestcaseCommand testcaseCommand, BindingResult result, Model model) { Webarchive webarchive;//from ww w. j ava2 s . c om Account currentUser; Testcase newTestcase; TestcasePresentation testcasePresentation; NewTestcaseValidator newTestcaseValidator = new NewTestcaseValidator(referenceTestDataService, referenceDataService, testcaseDataService, resultDataService, webarchiveDataService, NewTestcaseValidator.Step.STEP_WEBARCHIVE); // validate command newTestcaseValidator.validate(testcaseCommand, result); if (result.hasErrors()) { if (result.hasFieldErrors(FormKeyStore.ID_TEST_KEY) || result.hasFieldErrors(FormKeyStore.ID_RESULT_KEY)) { // return to the first step if we have an error on the test or result id return displayAddTestcaseForm(model, testcaseCommand); } else { // return to the second step return displayAttachWebarchiveForm(model, testcaseCommand); } } // handle login and breadcrumb handleUserLoginForm(model); handleBreadcrumbTrail(model); // sanity check currentUser = AccountUtils.getInstance().getCurrentUser(); if (currentUser == null) { LogFactory.getLog(TestcaseController.class).error( "An unauthentified user reached testcase/add-finalize. Check spring security configuration."); return "guest/login"; } // get webarchive if (!testcaseCommand.isOnCreateWebarchive()) { webarchive = webarchiveDataService.read(testcaseCommand.getIdWebarchive()); // Tells the view to display an informative message about the time needed for the webarchive to be available model.addAttribute("webarchiveCreation", false); } else { webarchive = webarchiveController.createWebarchive(currentUser, testcaseCommand.getUrlNewWebarchive(), testcaseCommand.getDescriptionNewWebarchive()); if (webarchive != null) { // persist the webarchive webarchiveDataService.saveOrUpdate(webarchive); } // a null webarchive is handled below model.addAttribute("webarchiveCreation", true); } // sanity check if (webarchive == null) { // most of the time, if the webarchive is null, it means its creation // fails. model.addAttribute(FormKeyStore.GENERAL_ERROR_MESSAGE_KEY, MessageKeyStore.CANNOT_CREATE_WEBARCHIVE); // return to the second step return displayAttachWebarchiveForm(model, testcaseCommand); } // create testcase newTestcase = testcaseDataService.createFromTest(currentUser, webarchive, resultDataService.read(testcaseCommand.getIdResult()), referenceTestDataService.read(testcaseCommand.getIdReferenceTest()), testcaseCommand.getDescription()); // persist testcase testcaseDataService.saveOrUpdate(newTestcase); // email notification sendTestcaseCreationNotification(newTestcase); // display testcase testcasePresentation = testcasePresentationFactory.create(newTestcase); model.addAttribute("testcase", testcasePresentation); return "testcase/add-summary"; }
From source file:org.springframework.test.web.portlet.server.result.ModelResultMatchers.java
public PortletResultMatcher attributeHasFieldErrors(final String name, final String... fieldNames) { return new PortletResultMatcher() { public void match(PortletMvcResult PortletMvcResult) throws Exception { Map<String, Object> model = getModel(PortletMvcResult); BindingResult result = BindingResultUtils.getRequiredBindingResult(model, name); assertTrue("No errors for attribute: '" + name + "'", result.hasErrors()); for (final String fieldName : fieldNames) { assertTrue("No errors for field: '" + fieldName + "' of attribute: " + name, result.hasFieldErrors(fieldName)); }//www .jav a 2s . c om } }; }