• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error handling in struts

 
Kevin Lam
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can anyone tell me what object is the html:error tag looking at please? I am new to struts, I know that the validate() method in actionform would throws errors and the jsp will populate the original data with a list of errors displayed on the top of the page...

But how can I add my own exception to that error list please? Is it possible? Do I need to populate the form myself? or is there a way which I can throw exceptions/errors to the jsp page just like how validate() method does it??

Many thx

Kevin
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <html:errors> tag uses the ActionErrors class, which contains a collection of ActionError (V1.1) or ActionMessage (V1.2 & above) objects. To add a new message, just use the add() method of this object. You place this object in request scope by using the saveErrors() method of the Action class (Which is your action's superclass). If you're setting an error condition in the validate() method of an ActionForm, just make sure you've added an ActionError to the ActionErrors object before it is returned from the method.

For more information on this, see the user documentation available at http://struts.apache.org
 
Kevin Lam
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thx
 
Kevin Lam
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could I just ask one more question, how do I retain the properties and beans on the the errored form when an error is thrown?

KEv
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic