Hello everyone.
By some reason I cannot get to work the BindingResult on the POST of my form. I can submit the form I see the validator being executed, I can see the errors being added and even I'm printing the errors out to see if they are there (they are) but for some reason when the view gets rendered It only sees the model inside the BindingResult but no the errors. Any Ideas?
Form Controller snippet of the POST method.
View (Velocity):Code:@RequestMapping(method = RequestMethod.POST) public String processSubmit(@ModelAttribute("category") CategoryModel category, BindingResult result) { logger.info("saving category: " + category); new CategoryValidator().validate(category, result); if (result.hasErrors()) { //logger.info(result.toString()); //logger.info(category.toString()); logger.info(result.toString()); Iterator<ObjectError> iter = (result.getAllErrors()).iterator(); while(iter.hasNext()) { ObjectError oe = iter.next(); logger.info("OBJECT ERROR: CODE -> " + oe.getCode() + " MESSAGE -> " + oe.getCodes()); } return "categories/add"; } else { categoriesManager.saveCategory(category); }
And the validator:Code:<html> <head> <title>#springMessage("category.add")</title> <style> .error { color: red; } </style> </head> <body> <h1>#springMessage("category.add")</h1> <form action="#springUrl('/categories/add')" method="POST"> #springFormHiddenInput("category.id" "") Name: #springFormInput("category.name" "") <br/> Key: #springFormInput("category.key" "") <br/> Description: #springFormTextarea("category.description" "") <br/> <br> #springShowErrors("<br>" "error") <br> <input type="submit" value="submit"/> <input type="button" value="Cancel" onclick="document.location='#springUrl('/categories/list')';"/> </form> <br> </body> </html>
Any help will be appreciated.Code:public class CategoryValidator implements Validator { /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); @Override public boolean supports(Class clazz) { return CategoryModel.class.equals(clazz); } @Override public void validate(Object obj, Errors errors) { CategoryModel cm = (CategoryModel) obj; if (cm == null) { errors.reject("category.form.error"); } else { logger.info("Validating name"); if ((cm.getName()).length() <= 0) { errors.rejectValue("name", "category.form.name.error", null, "category.form.name.error"); } } }
Thank you.


Reply With Quote