List of usage examples for org.springframework.validation BindingResult reject
void reject(String errorCode);
From source file:org.zht.framework.web.utils.FileUploadUtils.java
/** * ?/*from ww w.j av a 2 s . com*/ * * @param request ? * @param file * @param result ? * @param allowedExtension ? * @return */ public static final String upload(HttpServletRequest request, MultipartFile file, BindingResult result, String[] allowedExtension) { try { return upload(request, getDefaultBaseDir(), file, allowedExtension, DEFAULT_MAX_SIZE, true); } catch (IOException e) { result.reject("upload.server.error"); } catch (InvalidExtensionException.InvalidImageExtensionException e) { result.reject("upload.not.allow.image.extension"); } catch (InvalidExtensionException.InvalidFlashExtensionException e) { result.reject("upload.not.allow.flash.extension"); } catch (InvalidExtensionException.InvalidMediaExtensionException e) { result.reject("upload.not.allow.media.extension"); } catch (InvalidExtensionException e) { result.reject("upload.not.allow.extension"); } catch (FileUploadBase.FileSizeLimitExceededException e) { result.reject("upload.exceed.maxSize"); } catch (FileNameLengthLimitExceededException e) { result.reject("upload.filename.exceed.length"); } return null; }
From source file:cn.guoyukun.spring.web.upload.FileUploadUtils.java
/** * ?/* ww w. ja v a 2 s. c o m*/ * * @param request ? * @param file * @param result ? * @param allowedExtension ? * @return */ public static final String upload(HttpServletRequest request, MultipartFile file, BindingResult result, String[] allowedExtension) { try { return upload(request, getDefaultBaseDir(), file, allowedExtension, DEFAULT_MAX_SIZE, true); } catch (IOException e) { LogUtils.logError("file upload error", e); result.reject("upload.server.error"); } catch (InvalidExtensionException.InvalidImageExtensionException e) { result.reject("upload.not.allow.image.extension"); } catch (InvalidExtensionException.InvalidFlashExtensionException e) { result.reject("upload.not.allow.flash.extension"); } catch (InvalidExtensionException.InvalidMediaExtensionException e) { result.reject("upload.not.allow.media.extension"); } catch (InvalidExtensionException e) { result.reject("upload.not.allow.extension"); } catch (FileUploadBase.FileSizeLimitExceededException e) { result.reject("upload.exceed.maxSize"); } catch (FileNameLengthLimitExceededException e) { result.reject("upload.filename.exceed.length"); } return null; }
From source file:org.openmrs.module.registration.RegistrationUiUtils.java
public static void validateLatitudeAndLongitudeIfNecessary(PersonAddress address, BindingResult errors) { if (address != null) { AddressTemplate template = AddressSupport.getInstance().getAddressTemplate().get(0); if (StringUtils.isNotBlank(address.getLatitude())) { if (template.getElementRegex() != null && StringUtils.isBlank(template.getElementRegex().get("latitude"))) { if (!RegistrationUiUtils.isValidLatitude(address.getLatitude())) { errors.reject("registration.latitude.invalid"); }//w ww . j a v a 2 s . c om } } if (StringUtils.isNotBlank(address.getLongitude())) { if (template.getElementRegex() != null && StringUtils.isBlank(template.getElementRegex().get("longitude"))) { if (!RegistrationUiUtils.isValidLongitude(address.getLongitude())) { errors.reject("registration.longitude.invalid"); } } } } }
From source file:org.openmrs.module.fbregistrationapp.RegistrationAppUiUtils.java
public static void validateLatitudeAndLongitudeIfNecessary(PersonAddress address, BindingResult errors) { if (address != null) { AddressTemplate template = AddressSupport.getInstance().getAddressTemplate().get(0); if (StringUtils.isNotBlank(address.getLatitude())) { if (template.getElementRegex() != null && StringUtils.isBlank(template.getElementRegex().get("latitude"))) { if (!RegistrationAppUiUtils.isValidLatitude(address.getLatitude())) { errors.reject("fbregistrationapp.latitude.invalid"); }/*from ww w . j av a 2 s . c om*/ } } if (StringUtils.isNotBlank(address.getLongitude())) { if (template.getElementRegex() != null && StringUtils.isBlank(template.getElementRegex().get("longitude"))) { if (!RegistrationAppUiUtils.isValidLongitude(address.getLongitude())) { errors.reject("fbregistrationapp.longitude.invalid"); } } } } }
From source file:org.openmrs.module.OpenmrsLite.RegistrationAppUiUtils.java
public static void validateLatitudeAndLongitudeIfNecessary(PersonAddress address, BindingResult errors) { if (address != null) { AddressTemplate template = AddressSupport.getInstance().getAddressTemplate().get(0); if (StringUtils.isNotBlank(address.getLatitude())) { if (template.getElementRegex() != null && StringUtils.isBlank(template.getElementRegex().get("latitude"))) { if (!RegistrationAppUiUtils.isValidLatitude(address.getLatitude())) { errors.reject("OpenmrsLite.latitude.invalid"); }//from www . j a v a 2 s . co m } } if (StringUtils.isNotBlank(address.getLongitude())) { if (template.getElementRegex() != null && StringUtils.isBlank(template.getElementRegex().get("longitude"))) { if (!RegistrationAppUiUtils.isValidLongitude(address.getLongitude())) { errors.reject("OpenmrsLite.longitude.invalid"); } } } } }
From source file:com.eryansky.core.web.upload.FileUploadUtils.java
/** * ?/*from w w w .j ava2 s.c o m*/ * * @param request ? * @param file * @param result ? * @param allowedExtension ? * @return */ public static final String upload(HttpServletRequest request, MultipartFile file, BindingResult result, String[] allowedExtension) { try { return upload(request, getDefaultBaseDir(), file, allowedExtension, DEFAULT_MAX_SIZE, true, null); } catch (IOException e) { LogUtils.logError("file upload error", e); result.reject("upload.server.error"); } catch (InvalidExtensionException.InvalidImageExtensionException e) { result.reject("upload.not.allow.image.extension"); } catch (InvalidExtensionException.InvalidFlashExtensionException e) { result.reject("upload.not.allow.flash.extension"); } catch (InvalidExtensionException.InvalidMediaExtensionException e) { result.reject("upload.not.allow.media.extension"); } catch (InvalidExtensionException e) { result.reject("upload.not.allow.extension"); } catch (FileSizeLimitExceededException e) { result.reject("upload.exceed.maxSize"); } catch (FileNameLengthLimitExceededException e) { result.reject("upload.filename.exceed.length"); } return null; }
From source file:org.openmrs.module.basicexample.web.controller.openMRSnewManageController.java
@RequestMapping(value = "/module/basicexample/addDepartment.form", method = RequestMethod.POST) public String submitDepartment(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "action") String action, @ModelAttribute("department") openMRSnew department, BindingResult errors) { MessageSourceService mss = Context.getMessageSourceService(); openMRSnewService departmentService = Context.getService(openMRSnewService.class); if (!Context.isAuthenticated()) { errors.reject("department.auth.required"); } else if (mss.getMessage("department.purgeDepartment").equals(action)) { try {//from w w w. j ava 2 s.c o m departmentService.purgeDepartment(department); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "department.delete.success"); return "redirect:departmentList.list"; } catch (Exception ex) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "department.delete.failure"); log.error("Failed to delete department", ex); return "redirect:departmentForm.form?departmentId=" + request.getParameter("departmentId"); } } else { departmentService.saveDepartment(department); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "department.saved"); } return "redirect:departmentList.list"; }
From source file:org.openmrs.module.department.web.controller.DepartmentManageController.java
@RequestMapping(value = "/module/department/addDepartment.form", method = RequestMethod.POST) public String submitDepartment(WebRequest request, HttpSession httpSession, ModelMap model, @RequestParam(required = false, value = "action") String action, @ModelAttribute("department") Department department, BindingResult errors) { MessageSourceService mss = Context.getMessageSourceService(); DepartmentService departmentService = Context.getService(DepartmentService.class); if (!Context.isAuthenticated()) { errors.reject("department.auth.required"); } else if (mss.getMessage("department.purgeDepartment").equals(action)) { try {//from w ww.j a va 2 s . co m departmentService.purgeDepartment(department); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "department.delete.success"); return "redirect:manage.form"; } catch (Exception ex) { httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "department.delete.failure"); log.error("Failed to delete department", ex); return "redirect:departmentForm.form?departmentId=" + request.getParameter("departmentId"); } } else { departmentService.saveDepartment(department); httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "department.saved"); } return "redirect:manage.form"; }