Author: niallp Date: Thu Jun 8 12:08:02 2006 New Revision: 412834 URL: http://svn.apache.org/viewvc?rev=412834&view=rev Log: Fix for STR-2883 - Command corresponding to RequestProcessor.processCachedMessages() method is missing
Added: struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java (with props) Modified: struts/action/trunk/core/src/main/resources/org/apache/struts/chain/chain-config.xml struts/action/trunk/src/site/xdoc/userGuide/building_controller.xml Added: struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java URL: http://svn.apache.org/viewvc/struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java?rev=412834&view=auto ============================================================================== --- struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java (added) +++ struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java Thu Jun 8 12:08:02 2006 @@ -0,0 +1,73 @@ +/* + * $Id$ + * + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.struts.chain.commands; + +import java.util.Map; +import org.apache.struts.Globals; +import org.apache.struts.chain.contexts.ActionContext; +import org.apache.struts.action.ActionMessages; + +/** + * <p>Remove cached messages stored in the session.</p> + * + * @version $Id$ + * @since Struts 1.3.5 + */ +public class RemoveCachedMessages extends ActionCommandBase { + + /** + * <p>Removes any <code>ActionMessages</code> object stored in the session + * under <code>Globals.MESSAGE_KEY</code> and <code>Globals.ERROR_KEY</code> + * if the messages' <code>isAccessed</code> method returns true. This + * allows messages to be stored in the session, displayed one time, and be + * released here.</p> + * + * @param actionCtx The <code>Context</code> for the current request + * @return <code>false</code> so that processing continues + * @throws Exception on any error + */ + public boolean execute(ActionContext actionCtx) + throws Exception { + + // Get session scope + Map session = actionCtx.getSessionScope(); + + // Remove messages as needed + removeAccessedMessages(session, Globals.MESSAGE_KEY); + + // Remove error messages as needed + removeAccessedMessages(session, Globals.ERROR_KEY); + + return false; + } + + /** + * <p>Removes any <code>ActionMessages</code> object from the specified + * scope stored under the specified key if the messages' + * <code>isAccessed</code> method returns true. + * + * @param scope The scope to check for messages in. + * @param key The key the messages are stored under. + */ + private void removeAccessedMessages(Map scope, String key) { + ActionMessages messages = (ActionMessages)scope.get(key); + if (messages != null && messages.isAccessed()) { + scope.remove(key); + } + } +} Propchange: struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/action/trunk/core/src/main/java/org/apache/struts/chain/commands/RemoveCachedMessages.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/action/trunk/core/src/main/resources/org/apache/struts/chain/chain-config.xml URL: http://svn.apache.org/viewvc/struts/action/trunk/core/src/main/resources/org/apache/struts/chain/chain-config.xml?rev=412834&r1=412833&r2=412834&view=diff ============================================================================== --- struts/action/trunk/core/src/main/resources/org/apache/struts/chain/chain-config.xml (original) +++ struts/action/trunk/core/src/main/resources/org/apache/struts/chain/chain-config.xml Thu Jun 8 12:08:02 2006 @@ -87,6 +87,8 @@ point in the chain without modifying the standard definition. + processCachedMessages RemoveCachedMessages + processMapping SelectAction (which also does processPath) processRoles AuthorizeAction @@ -132,6 +134,11 @@ <!-- Set (if needed) the HTTP response content type --> <command className="org.apache.struts.chain.commands.servlet.SetContentType"/> + + + <!-- Remove messages cached in the Session --> + <command + className="org.apache.struts.chain.commands.RemoveCachedMessages"/> <!-- Identify the ActionConfig for this request --> Modified: struts/action/trunk/src/site/xdoc/userGuide/building_controller.xml URL: http://svn.apache.org/viewvc/struts/action/trunk/src/site/xdoc/userGuide/building_controller.xml?rev=412834&r1=412833&r2=412834&view=diff ============================================================================== --- struts/action/trunk/src/site/xdoc/userGuide/building_controller.xml (original) +++ struts/action/trunk/src/site/xdoc/userGuide/building_controller.xml Thu Jun 8 12:08:02 2006 @@ -245,6 +245,20 @@ <tr> <td> + RemoveCachedMessages + </td> + <td> + Removes any <code>ActionMessages</code> object stored + in the session under <code>Globals.MESSAGE_KEY</code> + and <code>Globals.ERROR_KEY</code> if the messages' + <code>isAccessed</code> method returns true. This + allows messages to be stored in the session, displayed + one time, and be released. + </td> + </tr> + + <tr> + <td> SetContentType </td> <td> @@ -513,6 +527,12 @@ support additional processing hooks at any point in the chain without modifying the standard definition. + </td> + </tr> + <tr> + <td> + processCachedMessages</td> + <td>RemoveCachedMessages </td> </tr> <tr>