List of usage examples for org.springframework.validation BindingResult getAllErrors
List<ObjectError> getAllErrors();
From source file:cec.easyshop.storefront.controllers.pages.CartPageController.java
@RequestMapping(value = "/update", method = RequestMethod.POST) public String updateCartQuantities(@RequestParam("entryNumber") final long entryNumber, final Model model, @Valid final UpdateQuantityForm form, final BindingResult bindingResult, final HttpServletRequest request, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { if (bindingResult.hasErrors()) { for (final ObjectError error : bindingResult.getAllErrors()) { if (error.getCode().equals("typeMismatch")) { GlobalMessages.addErrorMessage(model, "basket.error.quantity.invalid"); } else { GlobalMessages.addErrorMessage(model, error.getDefaultMessage()); }/*from www .jav a 2s . c o m*/ } } else if (getCartFacade().hasEntries()) { try { final CartModificationData cartModification = getCartFacade().updateCartEntry(entryNumber, form.getQuantity().longValue()); if (cartModification.getQuantity() == form.getQuantity().longValue()) { // Success if (cartModification.getQuantity() == 0) { // Success in removing entry GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "basket.page.message.remove"); } else { // Success in update quantity GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "basket.page.message.update"); } } else if (cartModification.getQuantity() > 0) { // Less than successful GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER, "basket.page.message.update.reducedNumberOfItemsAdded.lowStock", new Object[] { cartModification.getEntry().getProduct().getName(), cartModification.getQuantity(), form.getQuantity(), request.getRequestURL() .append(cartModification.getEntry().getProduct().getUrl()) }); } else { // No more stock available GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER, "basket.page.message.update.reducedNumberOfItemsAdded.noStock", new Object[] { cartModification.getEntry().getProduct().getName(), request .getRequestURL().append(cartModification.getEntry().getProduct().getUrl()) }); } // Redirect to the cart page on update success so that the browser doesn't re-post again return REDIRECT_PREFIX + "/cart"; } catch (final CommerceCartModificationException ex) { LOG.warn("Couldn't update product with the entry number: " + entryNumber + ".", ex); } } prepareDataForPage(model); model.addAttribute(WebConstants.BREADCRUMBS_KEY, resourceBreadcrumbBuilder.getBreadcrumbs("breadcrumb.cart")); model.addAttribute("pageType", PageType.CART.name()); return ControllerConstants.Views.Pages.Cart.CartPage; }
From source file:org.davidmendoza.esu.web.admin.ArticuloController.java
@RequestMapping(value = "/publicacion", method = RequestMethod.POST) public String nuevaPublicacion(@ModelAttribute("publicacion") Publicacion publicacion, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model, Principal principal) { publicacionValidator.validate(publicacion, bindingResult); if (bindingResult.hasErrors()) { log.warn("No se pudo crear la publicacion. {}", bindingResult.getAllErrors()); inicializaPublicacion(model, publicacion); return "admin/articulo/publicacion"; }/*from w w w . j a va 2 s .c o m*/ try { Usuario usuario = usuarioService.obtiene(principal.getName()); publicacion.setEditor(usuario); publicacionService.nueva(publicacion); } catch (Exception e) { log.error("No se pudo crear la publicacion", e); inicializaPublicacion(model, publicacion); bindingResult.reject("No se pudo crear la publicacion. {}", e.getMessage()); return "admin/articulo/publicacion"; } return "redirect:/admin/articulo/ver/" + publicacion.getArticulo().getId(); }
From source file:com.ctc.storefront.controllers.pages.CartPageController.java
@SuppressWarnings("boxing") @ResponseBody/*from w w w. j a v a 2 s .c om*/ @RequestMapping(value = "/updateMultiD", method = RequestMethod.POST) public CartData updateCartQuantitiesMultiD(@RequestParam("entryNumber") final Integer entryNumber, @RequestParam("productCode") final String productCode, final Model model, @Valid final UpdateQuantityForm form, final BindingResult bindingResult) { if (bindingResult.hasErrors()) { for (final ObjectError error : bindingResult.getAllErrors()) { if ("typeMismatch".equals(error.getCode())) { GlobalMessages.addErrorMessage(model, "basket.error.quantity.invalid"); } else { GlobalMessages.addErrorMessage(model, error.getDefaultMessage()); } } } else { try { final CartModificationData cartModification = getCartFacade() .updateCartEntry(getOrderEntryData(form.getQuantity(), productCode, entryNumber)); if (cartModification.getStatusCode().equals(SUCCESSFUL_MODIFICATION_CODE)) { GlobalMessages.addMessage(model, GlobalMessages.CONF_MESSAGES_HOLDER, cartModification.getStatusMessage(), null); } else if (!model.containsAttribute(ERROR_MSG_TYPE)) { GlobalMessages.addMessage(model, GlobalMessages.ERROR_MESSAGES_HOLDER, cartModification.getStatusMessage(), null); } } catch (final CommerceCartModificationException ex) { LOG.warn("Couldn't update product with the entry number: " + entryNumber + ".", ex); } } return getCartFacade().getSessionCart(); }
From source file:com.epam.cme.storefront.controllers.pages.TelcoGuidedSellingController.java
@RequestMapping(value = "/removeEntry", method = RequestMethod.POST) public String updateCartQuantities(@RequestParam("entryNumber") final long entryNumber, final Model model, @Valid final UpdateQuantityForm form, @RequestParam("bundleNo") final String bundleNo, @RequestParam("componentId") final String componentId, final BindingResult bindingResult, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { if (bindingResult.hasErrors()) { for (final ObjectError error : bindingResult.getAllErrors()) { if (error.getCode().equals("typeMismatch")) { GlobalMessages.addErrorMessage(model, "basket.error.quantity.invalid"); } else { GlobalMessages.addErrorMessage(model, error.getDefaultMessage()); }/*from w w w . j av a 2 s.c o m*/ } } else if (cartFacade.getSessionCart().getEntries() != null) { try { final CartModificationData cartModification = cartFacade.updateCartEntry(entryNumber, form.getQuantity().longValue()); if (cartModification.getQuantity() == form.getQuantity().longValue()) { // Success if (cartModification.getQuantity() == 0) { // Success in removing entry redirectModel.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER, Collections.singletonList("guidedselling.basket.page.message.removed")); } else { // Success in update quantity redirectModel.addFlashAttribute(GlobalMessages.CONF_MESSAGES_HOLDER, Collections.singletonList("basket.page.message.update")); } } else { // Less than successful if (form.getQuantity().longValue() == 0) { // Failed to remove entry redirectModel.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER, Collections.singletonList("basket.information.quantity.reducedNumberOfItemsAdded." + cartModification.getStatusCode())); } else { // Failed to update quantity redirectModel.addFlashAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER, Collections.singletonList("basket.information.quantity.reducedNumberOfItemsAdded." + cartModification.getStatusCode())); } } return REDIRECT_PREFIX + "/bundle/edit-component/" + bundleNo + "/component/" + componentId; } catch (final CommerceCartModificationException ex) { LOG.warn("Couldn't update product with the entry number: " + entryNumber + ".", ex); return REDIRECT_PREFIX + "/bundle/edit-component/" + bundleNo + "/component/" + componentId; } } return REDIRECT_PREFIX + "/cart"; }
From source file:es.ucm.fdi.dalgs.competence.web.CompetenceController.java
@RequestMapping(value = "/degree/{degreeId}/competence/upload.htm", method = RequestMethod.POST) public String uploadPost(@ModelAttribute("newUpload") @Valid UploadForm upload, BindingResult resultBinding, Model model, @PathVariable("degreeId") Long id_degree, RedirectAttributes attr, Locale locale) { if (resultBinding.hasErrors() || upload.getCharset().isEmpty() || upload.getFileData().getSize() == 0) { for (ObjectError error : resultBinding.getAllErrors()) { System.err.println("Error: " + error.getCode() + " - " + error.getDefaultMessage()); }//from w w w. ja v a 2s. c om return "upload"; } ResultClass<Boolean> result = serviceCompetence.uploadCSV(upload, id_degree, locale); if (!result.hasErrors()) return "redirect:/degree/" + id_degree + ".htm"; else { attr.addFlashAttribute("errors", result.getErrorsList()); return "redirect:/degree/" + id_degree + "/competence/upload.htm"; } }
From source file:net.sf.sze.frontend.zeugnis.SchulamtsBemerkungController.java
/** * Speichert die neu angelegte Bemerkung. * @param halbjahrId die Id des Schulhalbjahres * @param klassenId die Id der Klasse/*from www . ja va2s . c o m*/ * @param schuelerId die Id des Schuelers * @param schulamtsBemerkung die Schulamtsbemerkung. * @param action die als nchstes auszufhrende Aktion. * @param model das Model * @param result das Bindingresult. * @return die logische View */ @RequestMapping(value = URL.ZeugnisPath.SCHULAMTS_BEMERKUNG_CREATE, method = RequestMethod.POST) public String insertSchulamtsBemerkung(@PathVariable(URL.Session.P_HALBJAHR_ID) Long halbjahrId, @PathVariable(URL.Session.P_KLASSEN_ID) Long klassenId, @PathVariable(URL.Session.P_SCHUELER_ID) Long schuelerId, @ModelAttribute("schulamtsBemerkung") SchulamtsBemerkung schulamtsBemerkung, BindingResult result, @RequestParam(value = URL.Common.P_ACTION, required = false) String action, Model model) { validator.validate(schulamtsBemerkung, result); if (result.hasErrors()) { LOG.info("Fehler beim Speichern der Schulamtsbemerkung: {}", result.getAllErrors()); model.addAttribute("insertUrl", URL.filledURLWithNamedParams(URL.ZeugnisPath.SCHULAMTS_BEMERKUNG_CREATE, URL.Session.P_HALBJAHR_ID, halbjahrId, URL.Session.P_KLASSEN_ID, klassenId, URL.Session.P_SCHUELER_ID, schuelerId)); fillModel(model, halbjahrId, klassenId, schuelerId, schulamtsBemerkung); return EDIT_SCHULAMTS_BEMERKUNG_VIEW; } LOG.debug("Create Bemerkung: " + schulamtsBemerkung); schulamtsBemerkungService.save(schulamtsBemerkung); final String nextUrl; if (StringUtils.equalsIgnoreCase(action, Common.ACTION_NEXT)) { nextUrl = URL.redirectWithNamedParams(URL.ZeugnisPath.SCHULAMTS_BEMERKUNG_CREATE, URL.Session.P_HALBJAHR_ID, halbjahrId, URL.Session.P_KLASSEN_ID, klassenId, URL.Session.P_SCHUELER_ID, schuelerId); } else { nextUrl = URL.createRedirectToZeugnisUrl(halbjahrId, klassenId, schuelerId); } return nextUrl; }
From source file:mx.gob.cfe.documentos.web.DocumentoController.java
@Transactional @RequestMapping(value = "/actualiza", method = RequestMethod.POST) public String actualiza(HttpServletRequest request, @Valid Documento documento, BindingResult bindingResult, Errors errors, Model modelo, RedirectAttributes redirectAttributes) { if (bindingResult.hasErrors()) { log.debug("eeror"); log.error("Hubo algun error en la forma, regresando"); for (ObjectError error : bindingResult.getAllErrors()) { log.debug("Error: {}", error); }/*from w w w . ja v a2s. c o m*/ modelo.addAttribute("documento", documento); return "documento/edita"; } try { log.debug("documento{}", documento.toString()); documento = instance.actualiza(documento); } catch (ConstraintViolationException e) { log.error("No se pudo crear la Asociacion", e); log.debug("exception"); modelo.addAttribute("documento", documento); return "documento/edita"; } redirectAttributes.addFlashAttribute("message", "asociacion.actualizada.message"); redirectAttributes.addFlashAttribute("messageAttrs", new String[] { documento.getAsunto() }); String tipo = documento.getTipoDocumento(); switch (tipo) { case "Circular": return "redirect:/circular/ver/" + documento.getId(); case "Memo": return "redirect:/memo/ver/" + documento.getId(); case "Memo Inter": return "redirect:/memoInter/ver/" + documento.getId(); case "Oficio": return "redirect:/oficio/ver/" + documento.getId(); } return "redirect:/documento/ver/" + documento.getId(); }
From source file:alpha.portal.webapp.controller.CardFileUploadControllerTest.java
/** * Test zero file.//from ww w . j a va2s . co m */ @Test public void testZeroFile() { final String caseId = "550e4713-e22b-11d4-a716-446655440000"; final String cardId = "440e4816-e01b-74d4-a716-449955440092"; final String fileName = "doesnotcompute.file"; final String mimeType = "text/plain"; final byte[] content = "".getBytes(); final MockHttpServletRequest request = this.newGet("/cardfileupload"); request.setRemoteUser("admin"); request.addParameter("case", caseId); request.addParameter("card", cardId); final FileUpload fileUpload = this.ctrl.showForm(request); fileUpload.setFile(content); final MockMultipartHttpServletRequest upload = new MockMultipartHttpServletRequest(); upload.setRemoteUser("user"); final MockMultipartFile file = new MockMultipartFile("file", fileName, mimeType, content); upload.addFile(file); upload.addParameter("case", caseId); upload.addParameter("card", cardId); final BindingResult errors = new DataBinder(fileUpload).getBindingResult(); String result = ""; try { result = this.ctrl.onSubmit(fileUpload, errors, upload); } catch (final IOException e) { Assert.fail("Should not fail on fail upload"); } Assert.assertTrue(errors.hasErrors()); final List<ObjectError> errorList = errors.getAllErrors(); Assert.assertEquals(1, errorList.size()); Assert.assertEquals("errors.required", errorList.get(0).getCode()); Assert.assertNull(upload.getSession().getAttribute("successMessages")); Assert.assertEquals("redirect:/cardfileupload?card=" + cardId + "&case=" + caseId, result); }