weaver 2003/03/23 17:02:17
Modified: src/java/org/apache/jetspeed/modules/actions/portlets
PortletAction.java
Log:
- Added an additional setTemplate() method signature that accepts a
boolean arg, persistent that sets the life time of the template to either the
current request or the entire portlet session using the portlet session state
- protected resetTemplate() method to remove the "template" attribute from the
portlet session state.
- getPortlet() convenience method added
- getTemplate() convenience method added
Revision Changes Path
1.2 +85 -4
jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PortletAction.java
Index: PortletAction.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/portlets/PortletAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PortletAction.java 20 Mar 2003 18:09:39 -0000 1.1
+++ PortletAction.java 24 Mar 2003 01:02:17 -0000 1.2
@@ -62,12 +62,14 @@
package org.apache.jetspeed.modules.actions.portlets;
import org.apache.jetspeed.portal.Portlet;
-
+import org.apache.jetspeed.portal.portlets.GenericMVCPortlet;
+import org.apache.jetspeed.util.PortletSessionState;
import org.apache.turbine.util.RunData;
-
import org.apache.velocity.context.Context;
+
+
/**
*
* Abstract holder for the portlet specific methods required above and
@@ -77,6 +79,7 @@
* encapsulates the event handling feature.
*
* @author tkuebler
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
* @version $Id$
* @stereotype moment-interval
*
@@ -134,15 +137,93 @@
/**
* This method is used when you want to short circuit an Action
- * and change the template that will be executed next.
+ * and change the template that will be executed next. The TTL
+ * for this is a single request.
*
* @param data Turbine information.
* @param template The template that will be executed next.
*/
public void setTemplate(RunData data, String template)
{
- getContext(data).put("template", template);
+ setTemplate(data, template, false);
}
+
+ /**
+ * This method is used when you want to short circuit an Action
+ * and change the template that will be executed next. If
+ * the <code>persistent</code> attribute is set to <i>true</i>
+ * the template value is stored in the portlet's session state
+ * and will be used until a new value has been set, either within
+ * portlet session or within the context. Regardless of the
+ * value of <code>persistent</code>, the context will ALWAYS
+ * have the correct "template" attribute set within.
+ *
+ * @param data Turbine information.
+ * @param template The template that will be executed next.
+ * @param persistent whether or not to make the template set
+ * persistent for the extent of the portlet session
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ */
+ public void setTemplate(RunData data, String template, boolean persistent)
+ {
+ Portlet portlet = getPortlet(getContext(data));
+
+ if (template != null)
+ {
+ if (persistent)
+ {
+ PortletSessionState.setAttribute(
+ portlet,
+ data,
+ GenericMVCPortlet.TEMPLATE,
+ template);
+ }
+ else
+ {
+ // Make sure there is no ssession residue ;)
+ resetTemplate(data);
+ }
+
+ // Always make the current template is available within the
+ // context.
+ getContext(data).put("template", template);
+ }
+
+ }
+
+ /**
+ * Clears the PortletSessionState of the <code>template</code>
+ * attribute.
+ */
+ protected void resetTemplate(RunData data)
+ {
+ Portlet portlet = getPortlet(getContext(data));
+ PortletSessionState.clearAttribute(portlet, data,
GenericMVCPortlet.PORTLET);
+ }
+
+
+
+ public Portlet getPortlet(Context context)
+ {
+ return (Portlet) context.get(GenericMVCPortlet.PORTLET);
+ }
+ /**
+ * Retrieves the template for this PortletAction's Portlet.
+ * The Portlet <code>init()</code> will have already initialized
+ * the template value within the current context in this order:<br/>
+ * 1. From the PortletSessionState's "template" attribute <br />
+ * 2. From the PortletConfig's "template" parameter.<br /><br />
+ * However, the action may have overriden this value using
+ * any of the <code>setTemplate()</code> methods.
+ * @param Context context the context for this action's portlet.
+ * @return String Current view template for this action's portlet.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott T. Weaver</a>
+ */
+ public String getTemplate(Context context)
+ {
+
+ return (String) context.get(GenericMVCPortlet.TEMPLATE);
+ }
protected abstract void buildConfigureContext(Portlet portlet, Context context,
RunData data)
throws Exception;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]