--- Robert Leland <[EMAIL PROTECTED]> wrote:If the solution can automatically clean up after itself, no matter what scenario that is thrown at it, then I am +1.
[EMAIL PROTECTED] wrote:
David,
I thought you were going to back this out ?
The conversation was left with me proposing a solution and asking for Martin's thoughts on it. He hasn't responded so I haven't backed it out.
Saving messages in the session is a commonly requested feature (and one
that I need) so I think it needs a solution.
If there is *--any--* usecase where the session can be left with the messages still in the session, then I am -1.
What ever goes into the session must be explicitly managed, which is usually handled from
the struts-config.xml, such as the ActionForm lifecycle.
-Rob
Action.saveMessages() that
saves them in the session is part of that solution. The other, is a class
I wrote called SingleUseActionMessages that only returns its messages one
time. I can commit SingleUseActionMessages if it's needed or we can come
up with a better solution.
David
-Rob/home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v
dgraham 2003/08/19 16:20:46jakarta-struts/src/share/org/apache/struts/action/Action.java
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
Index: Action.java
===================================================================
RCS file:
retrieving revision 1.66Otherwise,
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 <html:messages> tag (if
* messages="true" is set), if any messages are required.
* ensure that the request attribute is not created.empty
*
- * @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
+ * messages removes any existing ActionMessages in the request.Otherwise,
+ * * @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 <html:messages> tag (if
+ * messages="true" is set), if any messages are required.
+ * ensure that the session attribute is not created.empty
+ *
+ * @param session The session to save the messages in.
+ * @param messages The messages to save. <code>null</code> or
+ * messages removes any existing ActionMessages in the session.creating
+ * + * @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,
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- 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]