I have a form with few validations on it.
During new form submission, if validation fails I can see those error messages.
but, during editing the form when I change the field to blank intentionally and submit the form error messages are not shown on Jsp page but I can get the errorcount in controller as 1 .

2 Answers
2

Preserving the validation error messages can be a real pain!
I have tried a lot of things - from configuring the redirect behavior of the portlet container to using jsr303 instead of spring validation.

The only solution I have consistently had and success implementing is really ugly:

Do the validation in an action method.

If errors are encountered save the BindingResult/Errors-object with "your own key" in the Spring model and interrupt the action handling.

You are redirected to the render method

There you pick up the Errors-object and put it back to the key where "Spring validation" expects it.

The information stored in the Model under "org.springframework.validation.BindingResult.*" are deleted automatically between the action processing and the render processing, and by preserving it explicitly in "errors" the information will be available to the view.

This is an ugly solution, you have to know more than you want about how the implementation really works, it is counter intuitive and if not properly commented this code could easily be removed by someone not familiar with the problem, but it is not a lot of code and it works.