List of usage examples for org.springframework.validation FieldError FieldError
public FieldError(String objectName, String field, String defaultMessage)
From source file:edu.uiowa.icts.bluebutton.controller.ClinicalDocumentController.java
@RequestMapping(value = "save.html", method = RequestMethod.POST) public String save(@RequestParam("person.personId") Integer person_personId, @Valid @ModelAttribute("clinicalDocument") ClinicalDocument clinicalDocument, BindingResult result, // must immediately follow bound object @RequestParam("file") MultipartFile document, Model model) throws IOException { if (document.isEmpty()) { result.addError(new FieldError("clinicalDocument", "document", "may not be empty")); }/* w ww. j a v a 2s .c o m*/ if (result.hasErrors()) { model.addAttribute("personList", bluebuttonDaoService.getPersonService().list()); return "/bluebutton/clinicaldocument/edit"; } else { clinicalDocument.setPerson(bluebuttonDaoService.getPersonService().findById(person_personId)); clinicalDocument.setDocument(document.getBytes()); clinicalDocument.setName(document.getOriginalFilename()); clinicalDocument.setDateUploaded(new Date()); bluebuttonDaoService.getClinicalDocumentService().saveOrUpdate(clinicalDocument); return "redirect:/clinicaldocument/confirm?clinicalDocumentId=" + clinicalDocument.getClinicalDocumentId(); } }
From source file:edu.uiowa.icts.bluebutton.controller.ClinicalDocumentController.java
@RequestMapping(value = "confirm", method = RequestMethod.POST) public String confirmSave(@ModelAttribute("clinicalDocument") ClinicalDocument clinicalDocument, Model model, BindingResult result) {// ww w.ja v a 2s . c om ClinicalDocument cd = this.bluebuttonDaoService.getClinicalDocumentService() .findById(clinicalDocument.getClinicalDocumentId()); if (clinicalDocument.getSource() == null || clinicalDocument.getSource().trim().length() < 1) { result.addError(new FieldError("clinicalDocument", "source", "May not be empty")); } if (result.hasErrors()) { clinicalDocument.setDocument(cd.getDocument()); model.addAttribute("clinicalDocument", clinicalDocument); return "/bluebutton/clinicaldocument/confirmSource"; } else { cd.setParsedJson(clinicalDocument.getParsedJson()); cd.setSource(clinicalDocument.getSource().trim()); cd.setJsonParserVersion("1.0.0"); bluebuttonDaoService.getClinicalDocumentService().update(cd); return "redirect:/person/show?personId=".concat(cd.getPerson().getPersonId().toString()); } }
From source file:org.hoteia.qalingo.core.web.mvc.controller.AbstractQalingoController.java
protected void addMessageError(BindingResult result, Exception e, String formKey, String fieldKey, String errorMessage) {/* w ww.j a v a2s. co m*/ if (StringUtils.isEmpty(errorMessage)) { errorMessage = ""; // EMPTY VALUE TO EVENT VELOCITY MethodInvocationException } FieldError error = new FieldError(formKey, fieldKey, errorMessage); result.addError(error); result.rejectValue(error.getField(), ""); if (e != null) { logger.error(errorMessage, e); } else { logger.warn(errorMessage); } }
From source file:org.jtalks.jcommune.web.controller.UserController.java
/** * Tries to restore a password by email. * If e-mail given has not been registered * before view with an error will be returned. * * @param dto with email address to identify the user * @param result email validation result * @return view with a parameters bound/*from w w w . j ava 2 s.c om*/ */ @RequestMapping(value = "/password/restore", method = RequestMethod.POST) public ModelAndView restorePassword(@Valid @ModelAttribute("dto") RestorePasswordDto dto, BindingResult result) { ModelAndView mav = new ModelAndView("restorePassword"); if (result.hasErrors()) { return mav; } try { userService.restorePassword(dto.getUserEmail()); mav.addObject("message", "label.restorePassword.completed"); } catch (MailingFailedException e) { result.addError(new FieldError("dto", "email", "email.failed")); } return mav; }
From source file:org.mifos.ui.pentaho.controller.PentahoReportingController.java
private void addErrorToBindingResult(PentahoValidationError validationError, BindingResult bindingResult) { ObjectError error;//from w w w . j a va 2 s. c o m if (validationError.isFieldError()) { error = new FieldError("pentahoReportFormBean", validationError.getParamName(), validationError.getParamName() + ": " + validationError.getErrorMessage()); } else { error = new ObjectError("pentahoReportFormBean", validationError.getErrorMessage()); } bindingResult.addError(error); }
From source file:org.springframework.xd.module.options.FlattenedCompositeModuleOptionsMetadata.java
@Override public ModuleOptions interpolate(Map<String, String> raw) throws BindException { @SuppressWarnings("serial") Map<ModuleOptionsMetadata, Map<String, String>> distributed = new HashMap<ModuleOptionsMetadata, Map<String, String>>() { @Override// w ww .j av a 2s . co m public Map<String, String> get(Object key) { Map<String, String> result = super.get(key); if (result == null) { result = new HashMap<String, String>(); this.put((ModuleOptionsMetadata) key, result); } return result; } }; Map<String, String> copy = new HashMap<String, String>(raw); // First, distribute raw input values to their corresponding MOM for (String key : raw.keySet()) { for (ModuleOptionsMetadata mom : momToSupportedOptions.keySet()) { Set<String> optionNames = momToSupportedOptions.get(mom); if (optionNames.contains(key)) { distributed.get(mom).put(key, copy.remove(key)); break; } } } if (copy.size() > 0) { // We're just interested in a container for errors BindingResult bindingResult = new MapBindingResult(new HashMap<String, Object>(), "flattened"); for (String pty : copy.keySet()) { bindingResult.addError( new FieldError("flattened", pty, String.format("option named '%s' is not supported", pty))); } throw new BindException(bindingResult); } // Then, interpolate per-MOM and remember which MOM is responsible for which exposed value // TODO: should be multimap, as several MOMs could expose the same value final Map<String, ModuleOptions> nameToOptions = new HashMap<String, ModuleOptions>(); for (ModuleOptionsMetadata mom : momToSupportedOptions.keySet()) { Map<String, String> rawValuesSubset = distributed.get(mom); ModuleOptions mo = mom.interpolate(rawValuesSubset); EnumerablePropertySource<?> propertySource = mo.asPropertySource(); for (String optionName : propertySource.getPropertyNames()) { /* * XD-1472: InputType treated as a special case. If the module defines a default value, do not replace * it with a null value (the global default) */ if (optionName.equals(INPUT_TYPE)) { if (propertySource.getProperty(optionName) != null) { nameToOptions.put(optionName, mo); } } else { nameToOptions.put(optionName, mo); } } } final Set<ModuleOptions> uniqueModuleOptions = new HashSet<ModuleOptions>(nameToOptions.values()); return new ModuleOptions() { @Override public EnumerablePropertySource<FlattenedCompositeModuleOptionsMetadata> asPropertySource() { String psName = String.format("flattened-%d", System.identityHashCode(FlattenedCompositeModuleOptionsMetadata.this)); return new EnumerablePropertySource<FlattenedCompositeModuleOptionsMetadata>(psName, FlattenedCompositeModuleOptionsMetadata.this) { @Override public String[] getPropertyNames() { String[] result = nameToOptions.keySet().toArray(new String[nameToOptions.keySet().size()]); FlattenedCompositeModuleOptionsMetadata.logger.debug(String.format( "returning propertyNames: %s", StringUtils.arrayToCommaDelimitedString(result))); return result; } @Override public Object getProperty(String name) { ModuleOptions moduleOptions = nameToOptions.get(name); return moduleOptions == null ? null : moduleOptions.asPropertySource().getProperty(name); } }; } @Override public String[] profilesToActivate() { List<String> result = new ArrayList<String>(); for (ModuleOptions delegate : uniqueModuleOptions) { result.addAll(Arrays.asList(delegate.profilesToActivate())); } return result.toArray(new String[result.size()]); } @Override public void validate() { for (ModuleOptions delegate : uniqueModuleOptions) { delegate.validate(); } } }; }
From source file:ru.org.linux.spring.AddRemoveBoxesController.java
@RequestMapping(value = "/add-box.jsp", method = RequestMethod.POST) public String doAdd(@ModelAttribute("form") EditBoxesForm form, BindingResult result, SessionStatus status, HttpServletRequest request)/*from w ww . j av a 2 s .com*/ throws IOException, UtilException, AccessViolationException, StorageException { new EditBoxesFormValidator().validate(form, result); ValidationUtils.rejectIfEmptyOrWhitespace(result, "boxName", "boxName.empty", "? ?"); if (StringUtils.isNotEmpty(form.getBoxName()) && !DefaultProfile.isBox(form.getBoxName())) { result.addError(new FieldError("boxName", "boxName.invalid", "? ?")); } if (result.hasErrors()) { return "add-box"; } Template t = Template.getTemplate(request); if (result.hasErrors()) { return "add-box"; } if (form.getPosition() == null) { form.setPosition(0); } String objectName = getObjectName(form, request); List<String> boxlets = new ArrayList<String>(t.getProf().getList(objectName)); CollectionUtils.filter(boxlets, DefaultProfile.getBoxPredicate()); if (boxlets.size() > form.position) { boxlets.add(form.position, form.boxName); } else { boxlets.add(form.boxName); } t.getProf().setList(objectName, boxlets); t.writeProfile(t.getProfileName()); status.setComplete(); return "redirect:/edit-boxes.jsp"; }
From source file:ru.org.linux.user.AddRemoveBoxesController.java
@RequestMapping(value = "/add-box.jsp", method = RequestMethod.POST) public String doAdd(@ModelAttribute("form") EditBoxesRequest form, BindingResult result, SessionStatus status, HttpServletRequest request) throws IOException, AccessViolationException, StorageException { new EditBoxesRequestValidator().validate(form, result); ValidationUtils.rejectIfEmptyOrWhitespace(result, "boxName", "boxName.empty", "? ?"); if (StringUtils.isNotEmpty(form.getBoxName()) && !DefaultProfile.isBox(form.getBoxName())) { result.addError(new FieldError("boxName", "boxName.invalid", "? ?")); }/*from www.j a v a 2 s.c o m*/ if (result.hasErrors()) { return "add-box"; } Template t = Template.getTemplate(request); if (result.hasErrors()) { return "add-box"; } if (form.getPosition() == null) { form.setPosition(0); } String objectName = getObjectName(form, request); List<String> boxlets = new ArrayList<String>(t.getProf().getList(objectName)); CollectionUtils.filter(boxlets, DefaultProfile.getBoxPredicate()); if (boxlets.size() > form.position) { boxlets.add(form.position, form.boxName); } else { boxlets.add(form.boxName); } t.getProf().setList(objectName, boxlets); t.writeProfile(t.getProfileName()); status.setComplete(); return "redirect:/edit-boxes.jsp"; }