You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2007/10/02 17:38:07 UTC
svn commit: r581283 - in
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation:
ConversationRequestParameterProvider.java
jsf/components/UISeparateConversationContext.java
Author: skitching
Date: Tue Oct 2 08:38:07 2007
New Revision: 581283
URL: http://svn.apache.org/viewvc?rev=581283&view=rev
Log:
Move the separationMode property to a more appropriate location, to avoid having the (potentially generic)
ConversationRequestParameterProvider referencing a specific JSF component.
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java?rev=581283&r1=581282&r2=581283&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java Tue Oct 2 08:38:07 2007
@@ -39,9 +39,40 @@
ConversationManager.CONVERSATION_CONTEXT_PARAM
};
+ private final static ThreadLocal inSeparationMode = new ThreadLocal();
+
+ /**
+ * Update a threadlocal flag indicating whether URLs written to the
+ * response page should have the special ConversationContext query
+ * parameter added to them or not.
+ * <p>
+ * Defaults to false (no separation), which means that urls ARE modified.
+ * <p>
+ * This can be called by a component before rendering its children in order to
+ * skip this url mangling. Any code that calls this method is responsible for
+ * restoring the original value at the appropriate time. This is very important,
+ * because this is a thread-local value that will be inherited by whatever
+ * request this pooled thread is reused for!
+ */
+ public static void setInSeparationMode(boolean separationMode)
+ {
+ // TODO: consider using a request-scope variable rather than a
+ // ThreadLocal; less damage if the flag is not reset..
+ inSeparationMode.set(separationMode ? Boolean.TRUE : Boolean.FALSE);
+ }
+
+ /**
+ * Returns true if URLs should be written out unmodified, false if they should
+ * have the conversation context id appended as a query parameter.
+ */
+ public static boolean isInSeparationMode()
+ {
+ return Boolean.TRUE.equals(inSeparationMode.get());
+ }
+
public String getFieldValue(String field)
{
- if (UISeparateConversationContext.isInSeparationMode())
+ if (isInSeparationMode())
{
return null;
}
@@ -63,7 +94,7 @@
public String[] getFields()
{
- if (UISeparateConversationContext.isInSeparationMode())
+ if (isInSeparationMode())
{
return null;
}
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java?rev=581283&r1=581282&r2=581283&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/components/UISeparateConversationContext.java Tue Oct 2 08:38:07 2007
@@ -19,41 +19,43 @@
package org.apache.myfaces.orchestra.conversation.jsf.components;
-import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils;
+import java.io.IOException;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
-import java.io.IOException;
+
+import org.apache.myfaces.orchestra.conversation.ConversationRequestParameterProvider;
+import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils;
/**
- * <p>Embedded links will start a new conversation context</p>
- * <p/>
- * This will allow you to start a completely new context for conversations which
- * is the base for multi window awareness.
- * </p>
+ * Embedded links will start a new conversation context.
+ * <p>
+ * Use this as the ancestor of any clickable links that should cause the new page to
+ * run within a totally new set of conversations. This really only makes sense when
+ * those links cause a new window to open. That new window then acts completely
+ * independently of the original window (as long as data is stored in conversations,
+ * not directly in the http session).
+ * <p>
+ * Normally, all urls within a view are rendered with a query parameter holding the
+ * current conversation context id, causing a later request to that url to use the
+ * same context as was used to render the original page. This tag causes the query
+ * parameters to be omitted for all urls output by nested components. When any
+ * such url is invoked, the missing conversation context id then causes a new
+ * conversation context to be created.
*/
public class UISeparateConversationContext extends UIComponentBase
{
public static final String COMPONENT_FAMILY = "javax.faces.Component";
public static final String COMPONENT_TYPE = "org.apache.myfaces.orchestra.SeparateConversationContext";
- private final static ThreadLocal inSeperationMode = new ThreadLocal();
-
- private static void setInSeparationMode(boolean seperationMode)
- {
- inSeperationMode.set(seperationMode ? Boolean.TRUE : Boolean.FALSE);
- }
-
- public static boolean isInSeparationMode()
- {
- return Boolean.TRUE.equals(inSeperationMode.get());
- }
-
public void encodeBegin(FacesContext context) throws IOException
{
super.encodeBegin(context);
- setInSeparationMode(true);
+ // Stop appending the conversation context id to URLs. This means that a request using
+ // those urls will trigger a new conversation context rather than inheriting the one
+ // associated with this request.
+ ConversationRequestParameterProvider.setInSeparationMode(true);
}
public void encodeChildren(FacesContext context) throws IOException
@@ -64,7 +66,13 @@
}
finally
{
- setInSeparationMode(false);
+ // Restore the original separation mode. Actually, we just assume here that
+ // the original value was false. There's no reason for anyone to ever nest
+ // UISeparateConversationContext components, and nothing else fiddles with
+ // this flag so false is a reasonable assumption.
+ //
+ // TODO: actually save the original value?
+ ConversationRequestParameterProvider.setInSeparationMode(false);
}
}