In the nightly builds of Struts, which will be Struts 1.2, 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" ) ); 
   saveMessages( 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="true"> 
      <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 <code>saveMessages(request,ActionMessages)</code>, which saves the messages in request scope under a different key, Globals.MESSAGE_KEY. To display messages saved with <code>saveMessages(request,ActionMessages)</code>:

   <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.

StrutsDeprecatedActionErrors (last edited 2009-09-20 23:32:38 by localhost)