--- Martin Cooper <[EMAIL PROTECTED]> wrote:
> David,
> 
> Perhaps you missed my -1 on providing a means of saving errors in
> session
> scope unless an *automatic* means of removing them at the appropriate
> time
> can also be provided.
> 
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21408

Indeed, sorry I missed that.  The commit actually wasn't in response to
that bug but filled a need I had.  I often redirect to a success page to
prevent the user from refreshing the page.  Success messages should appear
on the page I redirect to.  

So, I added the saveMessages() that saves to the session and I wrote a
small subclass of ActionMessages that only displays the messages once. 
The object stays in the session until it's overwritten but the messages
are never displayed again.  I don't believe there's a way to remove them
from the session so this solution seemed to be the best way.

This is a rather common request from users and I could also add my
SingleUseActionMessages to Struts if needed. 

Are you still -1 on this?  If so, is there a better way of acheiving this
functionality?

David

> 
> --
> Martin Cooper
> 
> 
> <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > dgraham     2003/08/19 16:20:46
> >
> >   Modified:    src/share/org/apache/struts/action Action.java
> >   Log:
> >   Added version of saveMessages() that saves them into the session
> >   instead of the request.
> >
> >   Revision  Changes    Path
> >   1.67      +33 -8
> jakarta-struts/src/share/org/apache/struts/action/Action.java
> >
> >   Index: Action.java
> >   ===================================================================
> >   RCS file:
>
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v
> >   retrieving revision 1.66
> >   retrieving revision 1.67
> >   diff -u -r1.66 -r1.67
> >   --- Action.java 2 Aug 2003 21:12:16 -0000 1.66
> >   +++ Action.java 19 Aug 2003 23:20:45 -0000 1.67
> >   @@ -431,15 +431,16 @@
> >
> >        }
> >
> >   -
> >        /**
> >         * Save the specified messages keys into the appropriate
> request
> >         * attribute for use by the &lt;html:messages&gt; tag (if
> >         * messages="true" is set), if any messages are required.
> Otherwise,
> >         * ensure that the request attribute is not created.
> >         *
> >   -     * @param request   The servlet request we are processing
> >   -     * @param messages  Messages object
> >   +     * @param request The servlet request we are processing.
> >   +     * @param messages The messages to save. <code>null</code> or
> empty
> >   +     * messages removes any existing ActionMessages in the request.
> >   +     *
> >         * @since Struts 1.1
> >         */
> >        protected void saveMessages(
> >   @@ -454,9 +455,33 @@
> >
> >            // Save the messages we need
> >            request.setAttribute(Globals.MESSAGE_KEY, messages);
> >   -
> >        }
> >   +
> >   +    /**
> >   +     * Save the specified messages keys into the appropriate
> session
> >   +     * attribute for use by the &lt;html:messages&gt; tag (if
> >   +     * messages="true" is set), if any messages are required.
> Otherwise,
> >   +     * ensure that the session attribute is not created.
> >   +     *
> >   +     * @param session The session to save the messages in.
> >   +     * @param messages The messages to save. <code>null</code> or
> empty
> >   +     * messages removes any existing ActionMessages in the session.
> >   +     *
> >   +     * @since Struts 1.2
> >   +     */
> >   +    protected void saveMessages(
> >   +        HttpSession session,
> >   +        ActionMessages messages) {
> >   +
> >   +        // Remove any messages attribute if none are required
> >   +        if ((messages == null) || messages.isEmpty()) {
> >   +            session.removeAttribute(Globals.MESSAGE_KEY);
> >   +            return;
> >   +        }
> >
> >   +        // Save the messages we need
> >   +        session.setAttribute(Globals.MESSAGE_KEY, messages);
> >   +    }
> >
> >        /**
> >         * Save a new transaction token in the user's current session,
> creating
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to