[webbeans-commits] Webbeans SVN: r1931 - in ri/trunk/impl/src/main/java/org/jboss/webbeans: jsf and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Wed Mar 11 18:42:39 EDT 2009


Author: nickarls
Date: 2009-03-11 18:42:39 -0400 (Wed, 11 Mar 2009)
New Revision: 1931

Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ConversationImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
Log:
Switch to attribute in view root for conversation propagation (thanks for the tip, Dan). 
Name ConversationImpl to javax.webbeans.conversation

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ConversationImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ConversationImpl.java	2009-03-11 19:01:29 UTC (rev 1930)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/conversation/ConversationImpl.java	2009-03-11 22:42:39 UTC (rev 1931)
@@ -34,7 +34,7 @@
  * @see javax.context.Conversation
  */
 @RequestScoped
- at Named("conversation")
+ at Named("javax.webbeans.conversation")
 @Standard
 public class ConversationImpl implements Conversation
 {
@@ -73,6 +73,7 @@
     * Initializes a new conversation
     * 
     * @param conversationIdGenerator The conversation ID generator
+    * @param timeout The conversation inactivity timeout
     */
    @Initializer
    public void init(ConversationIdGenerator conversationIdGenerator, @ConversationInactivityTimeout long timeout)
@@ -91,6 +92,8 @@
 
    public void begin(String id)
    {
+      // Store away the (first) change to the conversation ID. If the original conversation was long-running,
+      // we might have to place it back for termination once the request is over.
       if (originalCid == null)
       {
          originalCid = cid;
@@ -128,7 +131,7 @@
    /**
     * Assumes the identity of another conversation
     * 
-    * @param conversation The new conversation identity
+    * @param conversation The new conversation
     * 
     */
    public void switchTo(Conversation conversation)
@@ -143,7 +146,7 @@
    @Override
    public String toString()
    {
-      return "ID: " + cid + ", long-running: " + longRunning + ", timeout: " + timeout;
+      return "ID: " + cid + ", long-running: " + longRunning + ", timeout: " + timeout + "ms";
    }
 
    public void setLongRunning(boolean longRunning)

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java	2009-03-11 19:01:29 UTC (rev 1930)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/PhaseHelper.java	2009-03-11 22:42:39 UTC (rev 1931)
@@ -16,7 +16,6 @@
  */
 package org.jboss.webbeans.jsf;
 
-import javax.faces.component.html.HtmlInputHidden;
 import javax.faces.context.FacesContext;
 import javax.inject.AnnotationLiteral;
 import javax.servlet.http.HttpSession;
@@ -36,7 +35,7 @@
 {
    private static LogProvider log = Logging.getLogProvider(PhaseHelper.class);
 
-   private static final String CONVERSATION_PROPAGATION_COMPONENT_ID = "webbeans_conversation_propagation";
+   private static final String CONVERSATION_PROPAGATION_KEY = "webbeans_conversation_propagationz";
 
    /**
     * Gets a FacesContext instance
@@ -59,49 +58,18 @@
    }
 
    /**
-    * Removes the conversation propagation component from the ui view root
-    */
-   public static void removePropagationComponent()
-   {
-      log.debug("Removed propagation component");
-      HtmlInputHidden propagationComponent = getPropagationComponent();
-      if (propagationComponent != null)
-      {
-         context().getViewRoot().getChildren().remove(propagationComponent);
-      }
-   }
-
-   /**
     * Creates and/or updates the conversation propagation component in the UI
     * view root
     * 
     * @param cid The conversation id to propagate
     */
-   public static void createOrUpdatePropagationComponent(String cid)
+   public static void propagateConversation(String cid)
    {
-      HtmlInputHidden propagationComponent = getPropagationComponent();
-      if (propagationComponent == null)
-      {
-         log.trace("Created propagation component");
-         propagationComponent = (HtmlInputHidden) context().getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE);
-         propagationComponent.setId(CONVERSATION_PROPAGATION_COMPONENT_ID);
-         context().getViewRoot().getChildren().add(propagationComponent);
-      }
+      context().getViewRoot().getAttributes().put(CONVERSATION_PROPAGATION_KEY, cid);
       log.debug("Updated propagation component with cid " + cid);
-      propagationComponent.setValue(cid);
    }
 
    /**
-    * Gets the propagation component from the UI view root
-    * 
-    * @return The component (or null if not found)
-    */
-   private static HtmlInputHidden getPropagationComponent()
-   {
-      return (HtmlInputHidden) context().getViewRoot().findComponent(CONVERSATION_PROPAGATION_COMPONENT_ID);
-   }
-
-   /**
     * Gets the propagated conversation id parameter from the request
     * 
     * @return The conversation id (or null if not found)
@@ -115,18 +83,13 @@
    }
 
    /**
-    * Gets the propagated conversation id from the propagation component
+    * Gets the propagated conversation id from the view root attribute map
     * 
     * @return The conversation id (or null if not found)
     */
-   public static String getConversationIdFromPropagationComponent()
+   public static String getConversationIdFromViewRoot()
    {
-      String cid = null;
-      HtmlInputHidden propagationComponent = getPropagationComponent();
-      if (propagationComponent != null)
-      {
-         cid = propagationComponent.getValue().toString();
-      }
+      String cid = (String) context().getViewRoot().getAttributes().get(CONVERSATION_PROPAGATION_KEY);
       log.trace("Got cid " + cid + " from propagation component");
       return cid;
    }
@@ -141,7 +104,7 @@
       String cid = null;
       if (isPostback())
       {
-         cid = getConversationIdFromPropagationComponent();
+         cid = getConversationIdFromViewRoot();
       }
       else
       {
@@ -161,4 +124,12 @@
       return (HttpSession) context().getExternalContext().getSession(true);
    }
 
+   /**
+    * Stops conversation propagation through the view root
+    */
+   public static void stopConversationPropagation()
+   {
+      context().getViewRoot().getAttributes().remove(CONVERSATION_PROPAGATION_KEY);
+   }
+
 }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-03-11 19:01:29 UTC (rev 1930)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-03-11 22:42:39 UTC (rev 1931)
@@ -64,11 +64,11 @@
       Conversation conversation = CurrentManager.rootManager().getInstanceByType(Conversation.class);
       if (conversation.isLongRunning())
       {
-         PhaseHelper.createOrUpdatePropagationComponent(conversation.getId());
+         PhaseHelper.propagateConversation(conversation.getId());
       }
       else
       {
-         PhaseHelper.removePropagationComponent();
+         PhaseHelper.stopConversationPropagation();
       }
    }
 




More information about the weld-commits mailing list