Differences between revisions 6 and 7
Revision 6 as of 2005-04-05 19:42:41
Size: 2818
Comment:
Revision 7 as of 2009-09-20 23:12:07
Size: 2830
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
In the Struts 1.2.4 release, [http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionError.html ActionError] is deprecated. [http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionErrors.html ActionErrors] would be deprecated, except that it is part of the method signature for ActionForm.validate(). In the Struts 1.2.4 release, [[http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionError.html|ActionError]] is deprecated. [[http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionErrors.html|ActionErrors]] would be deprecated, except that it is part of the method signature for ActionForm.validate().
Line 25: Line 25:
This change was motivated by the realization that there are non-error messages that need to be communicated. Action now has an additional method '''saveMessages(request,ActionMessages)''', which saves the messages in request scope under a different key, [http://jakarta.apache.org/struts/api/org/apache/struts/Globals.html#MESSAGE_KEY Globals.MESSAGE_KEY]. To display messages saved with '''saveMessages''': This change was motivated by the realization that there are non-error messages that need to be communicated. Action now has an additional method '''saveMessages(request,ActionMessages)''', which saves the messages in request scope under a different key, [[http://jakarta.apache.org/struts/api/org/apache/struts/Globals.html#MESSAGE_KEY|Globals.MESSAGE_KEY]]. To display messages saved with '''saveMessages''':
Line 32: Line 32:
Finally, you can save an [http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMessages.html ActionMessages] object under an arbitrary key and display it with the html:messages tag: Finally, you can save an [[http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionMessages.html|ActionMessages]] object under an arbitrary key and display it with the html:messages tag:
Line 48: Line 48:
Of course, see the full [http://jakarta.apache.org/struts/userGuide/struts-html.html#messages html:messages] doc for details. Of course, see the full [[http://jakarta.apache.org/struts/userGuide/struts-html.html#messages|html:messages]] doc for details.
Line 55: Line 55:
Comment from Niall Pemberton: ''This page implies that the <html:messages> tag is the preferred way to handle messages - I don't agree with that. Wether you use <html:messages> or <html:errors> is just a matter of preference - see [http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html here] for a comparison. Comment from Niall Pemberton: ''This page implies that the <html:messages> tag is the preferred way to handle messages - I don't agree with that. Wether you use <html:messages> or <html:errors> is just a matter of preference - see [[http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html|here]] for a comparison.

In the Struts 1.2.4 release, ActionError is deprecated. ActionErrors would be deprecated, except that it is part of the method signature for ActionForm.validate().

After Struts 1.1, the preferred way to handle errors in your Java code is:

   ActionMessages am = new ActionMessages(); 
   am.add( ActionMessages.GLOBAL_MESSAGE,  
           new ActionMessage( "not.authorized.for.account" ) ); 
   saveErrors( request, am ); 

and to display those messages in the JSP:

   <html-el:messages id="msg" message="false"> 
      <c:out value="${msg}"/> 
   </html-el:messages> 

or if you are not using the struts-el tags:

   <html:messages id="msg" message="false"> 
      <bean:write name="msg" /> 
   </html:messages> 

This change was motivated by the realization that there are non-error messages that need to be communicated. Action now has an additional method saveMessages(request,ActionMessages), which saves the messages in request scope under a different key, Globals.MESSAGE_KEY. To display messages saved with saveMessages:

   <html-el:messages id="msg" message="true"> 
      <c:out value="${msg}"/> 
   </html-el:messages> 

Finally, you can save an ActionMessages object under an arbitrary key and display it with the html:messages tag:

  ActionMessages am = new ActionMessages(); 
   am.add( ActionMessages.GLOBAL_MESSAGE,  
           new ActionMessage( "msg.warning" ) ); 
  request.setAttribute("warnings", am); 

and in your page:

   <html-el:messages name="warnings" id="msg"> 
      <c:out value="${msg}"/> 
   </html-el:messages> 

Of course, see the full html:messages doc for details.

Comment from hauser@acm.org: So what do you recommend for somebody who already wants to use ActionMessages, but also has ValidatorForm?

Response: use ActionMessages anywhere except in an ActionForm. Soon we will provide an alternate method on ActionForm which returns an ActionMessages and lets us move forward with fully deprecating ActionErrors.

Comment from Niall Pemberton: This page implies that the <html:messages> tag is the preferred way to handle messages - I don't agree with that. Wether you use <html:messages> or <html:errors> is just a matter of preference - see here for a comparison.

StrutsDeprecatedActionErrors (last edited 2009-09-20 23:12:07 by localhost)