Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Error handling in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error handling in struts" Watch "Error handling in struts" New topic
Author

Error handling in struts

Kevin Lam
Ranch Hand

Joined: Oct 27, 2005
Posts: 68
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

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
Kevin Lam
Ranch Hand

Joined: Oct 27, 2005
Posts: 68
Many thx
Kevin Lam
Ranch Hand

Joined: Oct 27, 2005
Posts: 68
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
 
jQuery in Action, 2nd edition
 
subject: Error handling in struts
 
Similar Threads
Setting up form data
Struts Exception Handling
Forwarding to a different JSP on error
ActionMessages example?
ActionErrors from Action Class are not displaying in struts jsp page