2

I am developing a application using Spring MVC 3.0 frame work, I have following requirement,

There are multiple form in one jsp page. I am using ajax to submit each form. But after submitting, each form will go to different controller. In controller I will validate input data if there is any error I need to send validation result back to jsp page. Right now I am storing errors into a separate list and sending back to jsp through json response. I am not sure whether to use bindingResult.getAllErrors() or bindingResult.getFieldErrors() to get list of errors in my controller. What's the difference between both?

2 Answers 2

6
+100

getAllErrors()

By using bindingResult.getAllErrors you will get all errors, both global and field ones.

getFieldErrors()

By using bindingResult.getFieldErrors() you will get all errors associated with the given field.

Here is a useful Link that may help you understand difference between each better.

1
  • 2
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – JJJ
    Apr 17, 2013 at 5:48
1

getAllErrors() returns all errors, both Global and Field. getFieldErrors() only returns errors related to binding field values. I am not sure what a "Global" error is generated from, as I have never seen one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.