List of usage examples for org.springframework.validation BindingResult getAllErrors
List<ObjectError> getAllErrors();
From source file:sample.tomcat.jsp.MessageController.java
@RequestMapping(value = "/result", method = RequestMethod.GET) @ModelAttribute//from www . jav a 2 s . c om public String create(@Valid @ModelAttribute("message") Message message, BindingResult bindingResult, Model model, Research research, HttpServletRequest request) { if (bindingResult.hasErrors()) { logger.info("Validation errors:" + bindingResult.getAllErrors()); return "showForm"; } try { messageService.save(message); } catch (Exception e) { System.out.println("Failed to send message ....:" + e.getMessage()); } model.addAttribute(message); return "result"; }
From source file:org.openmrs.module.dataimporttool.web.controller.DataImportToolStartMigrationController.java
/** * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, java.lang.Object, * org.springframework.validation.BindException) *//*www. j a v a 2 s. c om*/ @RequestMapping(value = "/continueMigration", method = RequestMethod.POST) protected ModelAndView startMigration(@ModelAttribute("dit") DataImportTool dit, BindingResult result, SessionStatus status, ModelMap model) { // validate form entries validator.validate(dit, result); if (result.hasErrors()) { result.getAllErrors(); return new ModelAndView("/module/dataimporttool/addMigrationSettings"); } // add the new tag Context.getService(DataImportToolService.class).saveDataImportTool(dit); //receives the parameters from the previous page and continues. DataImportToolService ditService = Context.getService(DataImportToolService.class); //starts migration log.info("Starting Data Migration"); stat = ditService.doMigration(); // clears the command object from the session //status.setComplete(); if (stat == -1) return new ModelAndView(ERROR_FORM_VIEW); return new ModelAndView(NEXT_FORM_VIEW); }
From source file:org.smigo.user.password.PasswordController.java
@RequestMapping(value = "/change-password", method = RequestMethod.POST) @ResponseBody/*from w w w.j av a2s . c om*/ public List<ObjectError> changePassword(@RequestBody @Valid Password password, BindingResult result, @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) { if (result.hasErrors()) { response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } userHandler.updatePassword(user.getId(), password.getNewPassword()); return Collections.emptyList(); }
From source file:no.kantega.kwashc.server.controller.SiteController.java
@RequestMapping(value = "/save", method = RequestMethod.POST) public String saveSite(@Valid Site site, BindingResult result, Model model) { validateSite(site, result);//from ww w . j a va 2 s. c o m if (result.hasErrors()) { System.out.print("Site rejected due to validation errors: " + result.getAllErrors()); model.addAttribute("site", site); return "site/editSite"; } site = siteRepository.save(site); return "redirect:/site/" + site.getId() + "/"; }
From source file:org.wallride.web.controller.admin.article.ArticleCreateController.java
@RequestMapping(method = RequestMethod.POST, params = "draft") public @ResponseBody DomainObjectSavedModel saveAsDraft(@PathVariable String language, @Validated @ModelAttribute("form") ArticleCreateForm form, BindingResult errors, AuthorizedUser authorizedUser) throws BindException { if (errors.hasErrors()) { for (ObjectError error : errors.getAllErrors()) { if (!"validation.NotNull".equals(error.getCode())) { throw new BindException(errors); }/* ww w. j a va2 s .c o m*/ } } Article article = null; try { article = articleService.createArticle(form.buildArticleCreateRequest(), Post.Status.DRAFT, authorizedUser); } catch (EmptyCodeException e) { errors.rejectValue("code", "NotNull"); } catch (DuplicateCodeException e) { errors.rejectValue("code", "NotDuplicate"); } if (errors.hasErrors()) { logger.debug("Errors: {}", errors); throw new BindException(errors); } return new DomainObjectSavedModel<>(article); }
From source file:org.openmrs.module.billing.web.controller.main.AmbulanceBillAddController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, @RequestParam("driverId") Integer driverId, @RequestParam("ambulanceIds") Integer[] ambulanceIds, HttpServletRequest request, Object command, BindingResult binding) { validate(ambulanceIds, binding, request); if (binding.hasErrors()) { model.addAttribute("errors", binding.getAllErrors()); return "module/billing/main/ambulanceBillAdd"; }//from ww w . java 2 s .c om BillingService billingService = (BillingService) Context.getService(BillingService.class); Driver driver = billingService.getDriverById(driverId); AmbulanceBill ambulanceBill = new AmbulanceBill(); ambulanceBill.setDriver(driver); ambulanceBill.setCreatedDate(new Date()); ambulanceBill.setCreator(Context.getAuthenticatedUser()); Ambulance ambulance = null; Money itemAmount; Money totalAmount = new Money(BigDecimal.ZERO); for (Integer id : ambulanceIds) { ambulance = billingService.getAmbulanceById(id); BigDecimal amount = new BigDecimal(request.getParameter(id + "_amount")); itemAmount = new Money(amount); totalAmount = totalAmount.plus(itemAmount); Integer numberOfTrip = Integer.parseInt(request.getParameter(id + "_numOfTrip")); //ghanshyam 07/07/2012 New Requirement #305: Additional details in Ambulance Bill String patientName = (request.getParameter(id + "_patientName")); //ghanshyam 1/08/2012 feedback of New Requirement #305: Additional details in Ambulance Bill String receiptNumber = (request.getParameter(id + "_receiptNumber")); String origin = (request.getParameter(id + "_origin")); String destination = (request.getParameter(id + "_destination")); AmbulanceBillItem item = new AmbulanceBillItem(); item.setName(ambulance.getName()); item.setCreatedDate(new Date()); item.setNumberOfTrip(numberOfTrip); item.setAmbulance(ambulance); item.setAmbulanceBill(ambulanceBill); item.setAmount(itemAmount.getAmount()); //ghanshyam 07/07/2012 New Requirement #305: Additional details in Ambulance Bill item.setPatientName(patientName); item.setReceiptNumber(receiptNumber); item.setOrigin(origin); item.setDestination(destination); ambulanceBill.addBillItem(item); } ambulanceBill.setAmount(totalAmount.getAmount()); ambulanceBill.setReceipt(billingService.createReceipt()); ambulanceBill = billingService.saveAmbulanceBill(ambulanceBill); return "redirect:/module/billing/ambulanceBill.list?driverId=" + driverId + "&ambulanceBillId=" + ambulanceBill.getAmbulanceBillId(); }
From source file:org.openlmis.fulfillment.web.OrderFileTemplateController.java
/** * Allows updating order file templates. * * @param orderFileTemplateDto An order file template bound to the request body * @return ResponseEntity containing saved orderFileTemplate *///from w ww . java2 s . c o m @RequestMapping(value = "/orderFileTemplates", method = RequestMethod.PUT) @ResponseBody public OrderFileTemplateDto savedOrderFileTemplate( @RequestBody @Valid OrderFileTemplateDto orderFileTemplateDto, BindingResult bindingResult) { LOGGER.debug("Checking right to update order file template"); permissionService.canManageSystemSettings(); if (bindingResult.hasErrors()) { throw new ValidationException(bindingResult.getAllErrors().get(0).getDefaultMessage()); } OrderFileTemplate template = orderFileTemplateService.getOrderFileTemplate(); if (!template.getId().equals(orderFileTemplateDto.getId())) { throw new ValidationException(ERROR_ORDER_FILE_TEMPLATE_CREATION); } LOGGER.debug("Saving Order File Template"); template.importDto(orderFileTemplateDto); template = orderFileTemplateRepository.save(template); LOGGER.debug("Saved Order File Template with id: " + template.getId()); return OrderFileTemplateDto.newInstance(template); }
From source file:mx.com.quadrum.contratos.controller.crud.ContactoController.java
@ResponseBody @RequestMapping(value = "agregarContacto", method = RequestMethod.POST) public String agregarContacto(@Valid @ModelAttribute("contacto") Contacto contacto, BindingResult bindingResult, HttpSession session) {/*ww w. j a v a 2s . co m*/ if (session.getAttribute("usuario") == null) { return SESION_CADUCA; } if (bindingResult.hasErrors()) { for (ObjectError e : bindingResult.getAllErrors()) { System.out.println(e.getCode()); System.out.println(e.getDefaultMessage()); System.out.println(e.getObjectName()); System.out.println(e.toString()); } return ERROR_DATOS; } if (contactoService.existeCorreo(contacto.getMail())) { return "Error...#Ya existe un usuario con el correo que quiere ingresar."; } return contactoService.agregar(contacto); }
From source file:org.openmrs.module.billing.web.controller.main.TenderBillEditController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, @RequestParam("tenderBillId") Integer tenderBillId, @RequestParam("companyId") Integer companyId, @RequestParam("tenderIds") Integer[] tenderIds, @RequestParam("action") String action, HttpServletRequest request, Object command, BindingResult binding) { validateQty(tenderIds, binding, request); if (binding.hasErrors()) { model.addAttribute("errors", binding.getAllErrors()); return "module/billing/main/tenderBillAdd"; }//from w w w .j a v a 2s. c o m BillingService billingService = (BillingService) Context.getService(BillingService.class); TenderBill tenderBill = billingService.getTenderBillById(tenderBillId); if ("void".equalsIgnoreCase(action)) { tenderBill.setVoided(true); tenderBill.setVoidedDate(new Date()); for (TenderBillItem item : tenderBill.getBillItems()) { item.setVoided(true); item.setVoidedDate(new Date()); } billingService.saveTenderBill(tenderBill); return "redirect:/module/billing/tenderBill.list?companyId=" + companyId; } tenderBill.setPrinted(false); // void old items and reset amount Map<Integer, TenderBillItem> mapOldItems = new HashMap<Integer, TenderBillItem>(); for (TenderBillItem item : tenderBill.getBillItems()) { item.setVoided(true); item.setVoidedDate(new Date()); mapOldItems.put(item.getTenderBillItemId(), item); } tenderBill.setAmount(BigDecimal.ZERO); Tender tender = null; int quantity = 0; Money itemAmount; Money totalAmount = new Money(BigDecimal.ZERO); TenderBillItem item; for (Integer id : tenderIds) { tender = billingService.getTenderById(id); quantity = Integer.parseInt(request.getParameter(id + "_qty")); itemAmount = new Money(tender.getPrice()); itemAmount = itemAmount.times(quantity); totalAmount = totalAmount.plus(itemAmount); String sItemId = request.getParameter(id + "_itemId"); if (sItemId != null) { item = mapOldItems.get(Integer.parseInt(sItemId)); item.setVoided(false); item.setVoidedDate(null); item.setQuantity(quantity); item.setAmount(itemAmount.getAmount()); } else { item = new TenderBillItem(); item.setName(tender.getName() + "_" + tender.getNumber()); item.setCreatedDate(new Date()); item.setTender(tender); item.setUnitPrice(tender.getPrice()); item.setQuantity(quantity); item.setTenderBill(tenderBill); item.setAmount(itemAmount.getAmount()); tenderBill.addBillItem(item); } } tenderBill.setAmount(totalAmount.getAmount()); tenderBill = billingService.saveTenderBill(tenderBill); return "redirect:/module/billing/tenderBill.list?companyId=" + companyId + "&tenderBillId=" + tenderBill.getTenderBillId(); }