File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bind global errors to Spring form and throw them to view

 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Errors should be used for displaying validation errors.
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code I have provided works. I found it out from various articles.
 
Vyas Sanzgiri
Ranch Hand
Posts: 686
Chrome Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic