Meaningless Drivel is fun!*
The moose likes Spring and the fly likes Bind global errors to Spring form and throw them to view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Bind global errors to Spring form and throw them to view" Watch "Bind global errors to Spring form and throw them to view" New topic
Author

Bind global errors to Spring form and throw them to view

Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Is there any best practice when binding global errors to Spring form (say service class throws exceptions)? Do we use reject and spring:errors to deal with such case?


===Vyas Sanzgiri===
My Blog
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Errors should be used for displaying validation errors.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Can I have any sample code or web site. On the Spring web documentation they have just given field validation errors information.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

I am trying to handle basic errors in service class (not form validation errors). Below is my controller



JSP snippet:



I do not get any result in the JSP snippet. "Input" form binds and gets me the results but I do not see any output for the errors. Is there something obvious that I am missing?
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
I have never used ModelMap. But the following code:

It mean you add a map into a map. I doubt it would work.

Where did you get the example code?
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
You should ask in Spring Source forum also. I've very little experience in Spring Annotation. I'm afraid I couldn't help you much on this.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

The code I have provided works. I found it out from various articles.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

OK I got it. I changed name="input" instead of command and items="${errors.globalErrors}"



But now I have another issue -

I am trying to use the same page for another controller which is supposed to throw errors and this JSP should catch it. How am I supposed to show these errors?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bind global errors to Spring form and throw them to view