use of org.springframework.validation.ObjectError in project spring-framework by spring-projects.
the class EscapedErrors method escapeObjectError.
@SuppressWarnings("unchecked")
private <T extends ObjectError> T escapeObjectError(T source) {
if (source == null) {
return null;
}
if (source instanceof FieldError) {
FieldError fieldError = (FieldError) source;
Object value = fieldError.getRejectedValue();
if (value instanceof String) {
value = HtmlUtils.htmlEscape((String) value);
}
return (T) new FieldError(fieldError.getObjectName(), fieldError.getField(), value, fieldError.isBindingFailure(), fieldError.getCodes(), fieldError.getArguments(), HtmlUtils.htmlEscape(fieldError.getDefaultMessage()));
} else {
return (T) new ObjectError(source.getObjectName(), source.getCodes(), source.getArguments(), HtmlUtils.htmlEscape(source.getDefaultMessage()));
}
}
use of org.springframework.validation.ObjectError in project spring-framework by spring-projects.
the class WebExchangeBindException method getMessage.
/**
* Returns diagnostic information about the errors held in this object.
*/
@Override
@SuppressWarnings("OptionalGetWithoutIsPresent")
public String getMessage() {
MethodParameter parameter = getMethodParameter().get();
StringBuilder sb = new StringBuilder("Validation failed for argument at index ").append(parameter.getParameterIndex()).append(" in method: ").append(parameter.getMethod().toGenericString()).append(", with ").append(this.bindingResult.getErrorCount()).append(" error(s): ");
for (ObjectError error : this.bindingResult.getAllErrors()) {
sb.append("[").append(error).append("] ");
}
return sb.toString();
}
use of org.springframework.validation.ObjectError in project head by mifos.
the class DefineNewOfficeController method processFormSubmit.
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @RequestParam(value = PREVIEW_PARAM, required = false) String preview, @ModelAttribute("officeFormBean") @Valid OfficeFormBean officeFormBean, BindingResult result, SessionStatus status) {
ModelAndView modelAndView = new ModelAndView(REDIRECT_TO_ADMIN_SCREEN);
EditOfficeInformationController editOfficeInformationController = new EditOfficeInformationController(officeServiceFacade);
if (StringUtils.isNotBlank(cancel)) {
modelAndView.setViewName(REDIRECT_TO_ADMIN_SCREEN);
status.setComplete();
} else if (StringUtils.isNotBlank(preview)) {
if (result.hasErrors()) {
modelAndView.setViewName("defineNewOffice");
modelAndView.addObject("showError", "true");
if (!((!officeFormBean.getLevelId().equals("1") && StringUtils.isNotBlank(officeFormBean.getParentId())) || (officeFormBean.getLevelId().equals("1") && !StringUtils.isNotBlank(officeFormBean.getParentId())))) {
result.addError(new ObjectError("parentLevelId", "Please specify Parent Level name"));
}
} else {
if (!((!officeFormBean.getLevelId().equals("1") && StringUtils.isNotBlank(officeFormBean.getParentId())) || (officeFormBean.getLevelId().equals("1") && !StringUtils.isNotBlank(officeFormBean.getParentId())))) {
result.addError(new ObjectError("parentLevelId", "Please specify Parent Level name"));
modelAndView.addObject("showError", "true");
modelAndView.setViewName("defineNewOffice");
} else {
modelAndView.setViewName("previewOfficeDetails");
switch(Integer.parseInt(officeFormBean.getLevelId())) {
case 1:
officeFormBean.setOfficeLevelName("Head Office");
break;
case 2:
officeFormBean.setOfficeLevelName("Regional Office");
break;
case 3:
officeFormBean.setOfficeLevelName("Divisional Office");
break;
case 4:
officeFormBean.setOfficeLevelName("Area Office");
break;
default:
officeFormBean.setOfficeLevelName("Branch Office");
break;
}
}
/*modelAndView.addObject("officeTypes", editOfficeInformationController.getOfficeTypes("new"));
if(!officeFormBean.getLevelId().equals("1")){
modelAndView.addObject("parentOffices", editOfficeInformationController.getParentDetails(officeFormBean.getLevelId()));
officeFormBean.setParentOfficeName(officeServiceFacade.retrieveOfficeById(Short.parseShort(officeFormBean.getParentId())).getName());
}
modelAndView.addObject("officeFormBean", officeFormBean);*/
}
modelAndView.addObject("officeTypes", editOfficeInformationController.getOfficeTypes("new"));
if ((!officeFormBean.getLevelId().equals("1") && StringUtils.isNotBlank(officeFormBean.getLevelId()))) {
modelAndView.addObject("parentOffices", editOfficeInformationController.getParentDetails(officeFormBean.getLevelId()));
if (StringUtils.isNotBlank(officeFormBean.getParentId())) {
officeFormBean.setParentOfficeName(officeServiceFacade.retrieveOfficeById(Short.parseShort(officeFormBean.getParentId())).getName());
}
}
modelAndView.addObject("officeFormBean", officeFormBean);
} else {
modelAndView.setViewName("defineNewOffice");
modelAndView.addObject("officeTypes", editOfficeInformationController.getOfficeTypes("new"));
if (!officeFormBean.getLevelId().equals("1")) {
modelAndView.addObject("parentOffices", editOfficeInformationController.getParentDetails(officeFormBean.getLevelId()));
}
modelAndView.addObject("showError", "false");
}
return modelAndView;
}
use of org.springframework.validation.ObjectError in project head by mifos.
the class UploadLogoController method uploadNewLogo.
@RequestMapping(value = "/uploadNewLogo.ftl", method = RequestMethod.POST)
public String uploadNewLogo(@ModelAttribute LogoUpload logoUpload, BindingResult result, Model model, HttpServletRequest request) {
String[] availableContentTypes = { "image/png", "image/gif", "image/jpeg", "image/pjpeg" };
if (Arrays.asList(availableContentTypes).contains(logoUpload.getFile().getContentType())) {
try {
logoServiceFacade.uploadNewLogo(logoUpload.getFile());
model.addAttribute("success", true);
} catch (IOException e) {
result.addError(new ObjectError("logoUpload", messageSource.getMessage("admin.uploadLogo.ioexception", null, RequestContextUtils.getLocale(request))));
}
} else {
result.addError(new ObjectError("logoUpload", messageSource.getMessage("admin.uploadLogo.badType", null, RequestContextUtils.getLocale(request))));
}
return "uploadNewLogo";
}
use of org.springframework.validation.ObjectError in project head by mifos.
the class PentahoReportingController method addErrorToBindingResult.
private void addErrorToBindingResult(PentahoValidationError validationError, BindingResult bindingResult) {
ObjectError error;
if (validationError.isFieldError()) {
error = new FieldError("pentahoReportFormBean", validationError.getParamName(), validationError.getParamName() + ": " + validationError.getErrorMessage());
} else {
error = new ObjectError("pentahoReportFormBean", validationError.getErrorMessage());
}
bindingResult.addError(error);
}
Aggregations