I work with a front-end developer who writes JSP files. We have a form that is working correctly, except validation/binding/processing errors can't seem to be displayed with Spring's <form:errors/>
tag.
I've confirmed that the error is being set, and what is apparently the correct path for the errors. Supposedly <form:errors path="*" />
should render them all, regardless of path, but it shows nothing.
Do I need to get into the tag library source to deduce what's going wrong?
2 things I discovered.
1) make sure you specify the name of the form-bean / command object in the form tag
2) make sure you name your form-bean / command object by its class name. In the example above my class is com.abc.xyz.SalesOrder. If I call it "so" or "order" in the model then it will not show the errors.
Simple answer: <form:errors/> must be within a <form:form/> element in order to bind to the model's "command" object.
This is just for posterity's sake, seeing that an answer has already been accepted. I had the same symptoms myself, but the problem for me was that the form:form method attribute value is case-sensitive: i.e. method="post" will not show errors, while method="POST" will work fine. Of particular note here is that everything worked as expected -- The form view was displayed as expected since validation had failed EXCEPT that the errors were not visible in the final JSP.
This behavior will exist on any controller that extends AbstractFormController, since
does a "POST".equals instead of "POST".equalsIgnoreCase.
Don't know if I had the same problem. My problem was that I set the wrong value for @ModelAttribute. Having the value set to the commandName of the <form:form /> works fine.
Question - Why "form:error path="xyzProperty" doesn't print error on jsp?
Anserwer -
BindingResult does have objectName property which binds list of errors with commandName in your jsp.
Defualt objectName = your Object Name. eg if class name is MyCareerFB then objectName = myCareerFB. Mind the first character in small case, it follows bean nameing convention.
Keep commandName value in jsp same as objectName, else error wont be binded with object and jsp will never print error message.
You might have not used the right naming convention for the commandName form attribute. That was the problem I ran into. I had a class named "XYZTask" and I named the form commandName="xyztask". All the form mapping worked except I did not see the errors reported by the tag. I renamed my class to "XyzTask" and the form commandName="xyzTask", and the errors started working.