You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Geeta Ramani <gr...@terralink.com> on 2004/07/06 20:41:05 UTC

RE: Confused about ActionMessages

Erik: Here's an example:

In your Action class do:
try {
            service.insertEmployee( employeeDTO );
            ActionMessages messages = new ActionMessages();
            ActionMessage message = new ActionMessage("message.employee.insert.success",employeeDTO.getName() );
            messages.add( ActionMessages.GLOBAL_MESSAGE, message );
            saveMessages( request, messages );
            request.setAttribute("employee",employeeDTO);
            return (mapping.findForward("success"));
        }
        catch( DatabaseException de ) {
            ActionErrors errors = new ActionErrors();
            ActionError error = new ActionError("error.employee.databaseException");
            errors.add( ActionErrors.GLOBAL_ERROR, error );
            saveErrors( request, errors );
            return (mapping.findForward("error"));
        }

In your success.jsp:




> -----Original Message-----
> From: Erik Weber [mailto:erikweber@mindspring.com]
> Sent: Tuesday, July 06, 2004 2:45 PM
> To: Struts Users Mailing List
> Subject: Confused about ActionMessages
> 
> 
> Hello all.
> 
> I have successfully used ActionErrors in combination with the 
> html:errors tag, by adding errors under various keys and then simply 
> placing the <html:errors/> tag at the top of my JSP.
> 
> However, the ActionMessages class doesn't seem to act in 
> parallel to the 
> ActionErrors class, and neither does the html:messages tag 
> seem to act 
> just like the html:errors tag (for one, it has a required 
> attribute that 
> the docs don't explain very well). And I sure don't 
> understand all these 
> constants (GLOBAL_ERROR, ERROR_KEY, MESSAGE, ACTION_MESSAGE, etc). 
> What's for what?
> 
> Could someone please give me a quick and dirty example of using 
> ActionMessages to present a "Your data was saved" or similar 
> message on 
> the "success" page after a form action is processed?
> 
> In other words, could you show me how you are populating the 
> ActionMessages instance in your Action class, and then how you are 
> displaying the messages on your JSP?
> 
> You'll really be helping me out as I'm trying to show my client some 
> working pages soon! (I don't wanna cheat if I don't have to).
> 
> Thanks,
> Erik
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org