[webbeans-commits] Webbeans SVN: r1503 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: conversation/bindings and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Feb 13 06:52:35 EST 2009


Author: nickarls
Date: 2009-02-13 06:52:35 -0500 (Fri, 13 Feb 2009)
New Revision: 1503

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/bindings/ConversationIdName.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/JavaSEConversationTerminator.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/NumericConversationIdGenerator.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
Log:
Cleanup of phase listener (some conversation logic remains in WebBeansListener still, though)

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java	2009-02-12 23:03:39 UTC (rev 1502)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -23,6 +23,8 @@
 import javax.servlet.http.HttpSession;
 
 import org.jboss.webbeans.context.ConversationContext;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.ConversationBeanMap;
 
 /**
@@ -32,6 +34,8 @@
  */
 public class ConversationEntry
 {
+   private static LogProvider log = Logging.getLogProvider(ConversationEntry.class);
+
    // The conversation ID
    private String cid;
    // The handle to the asynchronous timeout task
@@ -50,6 +54,7 @@
       this.cid = cid;
       this.terminationHandle = terminationHandle;
       this.concurrencyLock = new ReentrantLock();
+      log.trace("Created new conversation entry for conversation " + cid);
    }
 
    /**
@@ -71,16 +76,26 @@
     */
    public boolean cancelTermination()
    {
-      return terminationHandle.cancel(false);
+      boolean success = terminationHandle.cancel(false);
+      if (success)
+      {
+         log.trace("Termination of conversation " + cid + " cancelled");
+      }
+      else
+      {
+         log.warn("Failed to cancel termination of conversation " + cid);
+      }
+      return success;
    }
 
    /**
-    * Destroys the conversation and it's associated conversational context 
+    * Destroys the conversation and it's associated conversational context
     * 
     * @param session The HTTP session for the backing context beanmap
     */
    public void destroy(HttpSession session)
    {
+      log.trace("Destroying conversation " + cid);
       if (!terminationHandle.isCancelled())
       {
          cancelTermination();
@@ -91,7 +106,7 @@
    }
 
    /**
-    * Attempts to lock the conversation for exclusive usage 
+    * Attempts to lock the conversation for exclusive usage
     * 
     * @param timeoutInMilliseconds The time in milliseconds to wait on the lock
     * @return True if lock was successful, false otherwise
@@ -99,24 +114,43 @@
     */
    public boolean lock(long timeoutInMilliseconds) throws InterruptedException
    {
-      return concurrencyLock.tryLock(timeoutInMilliseconds, TimeUnit.MILLISECONDS);
+      boolean success = concurrencyLock.tryLock(timeoutInMilliseconds, TimeUnit.MILLISECONDS);
+      if (success)
+      {
+         log.trace("Conversation " + cid + " locked");
+      }
+      else
+      {
+         log.warn("Failed to lock conversation " + cid + " in " + timeoutInMilliseconds + "ms");
+      }
+      return success;
    }
 
    /**
     * Attempts to unlock the conversation
     */
-   public void unlock()
+   public boolean unlock()
    {
-      concurrencyLock.unlock();
+      if (concurrencyLock.isHeldByCurrentThread())
+      {
+         log.debug("Unlocked conversation " + cid);
+         concurrencyLock.unlock();
+      }
+      else
+      {
+         log.warn("Unlock attempt by non-owner on conversation " + cid);
+      }
+      return !concurrencyLock.isLocked();
    }
 
    /**
-    * Re-schedules timeout termination 
+    * Re-schedules timeout termination
     * 
     * @param terminationHandle The fresh timeout termination handle
     */
    public void reScheduleTermination(Future<?> terminationHandle)
    {
+      log.trace("Conversation " + cid + " re-scheduled for termination");
       this.terminationHandle = terminationHandle;
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/JavaSEConversationTerminator.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/JavaSEConversationTerminator.java	2009-02-12 23:03:39 UTC (rev 1502)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/JavaSEConversationTerminator.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -25,6 +25,8 @@
 import javax.context.SessionScoped;
 
 import org.jboss.webbeans.WebBean;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
 
 /**
  * A ConversationTerminator implementation using Java SE scheduling
@@ -36,10 +38,13 @@
 @WebBean
 public class JavaSEConversationTerminator implements ConversationTerminator, Serializable
 {
+   private static LogProvider log = Logging.getLogProvider(JavaSEConversationTerminator.class);
+
    private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
 
    public Future<?> scheduleForTermination(Runnable terminationTask, long timeoutInMilliseconds)
    {
+      log.trace("Recieved a termination task to be run in " + timeoutInMilliseconds + "ms");
       return executor.schedule(terminationTask, timeoutInMilliseconds, TimeUnit.MILLISECONDS);
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/NumericConversationIdGenerator.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/NumericConversationIdGenerator.java	2009-02-12 23:03:39 UTC (rev 1502)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/NumericConversationIdGenerator.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -22,6 +22,8 @@
 import javax.context.SessionScoped;
 
 import org.jboss.webbeans.WebBean;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
 
 /**
  * A ConversationIdGenerator implementation using running numerical values
@@ -33,6 +35,7 @@
 @WebBean
 public class NumericConversationIdGenerator implements ConversationIdGenerator, Serializable
 {
+   private static LogProvider log = Logging.getLogProvider(NumericConversationIdGenerator.class);
    // The next conversation ID
    private AtomicInteger id;
 
@@ -46,7 +49,9 @@
 
    public String nextId()
    {
-      return String.valueOf(id.getAndIncrement());
+      int nextId = id.getAndIncrement();
+      log.trace("Generated new conversation id " + nextId);
+      return String.valueOf(nextId);
    }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java	2009-02-12 23:03:39 UTC (rev 1502)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -27,9 +27,9 @@
 import javax.servlet.http.HttpSession;
 
 import org.jboss.webbeans.WebBean;
-import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
 import org.jboss.webbeans.context.ConversationContext;
 import org.jboss.webbeans.conversation.bindings.ConversationConcurrentAccessTimeout;
+import org.jboss.webbeans.conversation.bindings.ConversationIdName;
 import org.jboss.webbeans.conversation.bindings.ConversationInactivityTimeout;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
@@ -44,9 +44,10 @@
 @WebBean
 public class ServletConversationManager implements ConversationManager, Serializable
 {
-   private static LogProvider log = Logging.getLogProvider(WebBeansBootstrap.class);
-   
-   private static final long CONVERSATION_TIMEOUT_IN_MS = 10 * 60 * 1000;
+   private static LogProvider log = Logging.getLogProvider(ServletConversationManager.class);
+
+   // FIXME short temp
+   private static final long CONVERSATION_TIMEOUT_IN_MS = 10 * 30 * 1000;
    private static final long CONVERSATION_CONCURRENT_ACCESS_TIMEOUT_IN_MS = 1 * 1000;
 
    // The conversation terminator
@@ -60,11 +61,12 @@
    // The current HTTP session
    @Current
    private HttpSession session;
-   
-   // The conversation timeout in milliseconds waiting for access to a blocked conversation 
+
+   // The conversation timeout in milliseconds waiting for access to a blocked
+   // conversation
    @ConversationConcurrentAccessTimeout
    private long concurrentAccessTimeout;
-   
+
    // The conversation inactivity timeout in milliseconds
    @ConversationInactivityTimeout
    private long inactivityTimeout;
@@ -80,35 +82,46 @@
       log.trace("Created " + getClass());
       longRunningConversations = new ConcurrentHashMap<String, ConversationEntry>();
    }
-   
+
    @Produces
    @ConversationInactivityTimeout
    @WebBean
-   public long getConversationTimeoutInMilliseconds()
+   public static long getConversationTimeoutInMilliseconds()
    {
+      log.trace("Produced conversation timeout " + CONVERSATION_TIMEOUT_IN_MS);
       return CONVERSATION_TIMEOUT_IN_MS;
    }
 
    @Produces
    @ConversationConcurrentAccessTimeout
    @WebBean
-   public long getConversationConcurrentAccessTimeout()
+   public static long getConversationConcurrentAccessTimeout()
    {
+      log.trace("Produced conversation concurrent access timeout " + CONVERSATION_CONCURRENT_ACCESS_TIMEOUT_IN_MS);
       return CONVERSATION_CONCURRENT_ACCESS_TIMEOUT_IN_MS;
    }
-   
+
+   @Produces
+   @ConversationIdName
+   @WebBean
+   public static String getConversationIdName()
+   {
+      return "cid";
+   }
+
    public void beginOrRestoreConversation(String cid)
    {
       if (cid == null)
       {
          // No incoming conversation ID, nothing to do here, continue with
          // a transient conversation
+         log.trace("No conversation id to restore");
          return;
       }
       if (!longRunningConversations.containsKey(cid))
       {
          // We got an incoming conversation ID but it was not in the map of
-         // known ones, nothing to do. Log and return to continue with a 
+         // known ones, nothing to do. Log and return to continue with a
          // transient conversation
          log.info("Could not restore long-running conversation " + cid);
          return;
@@ -128,12 +141,12 @@
          log.debug("Interrupted while trying to acquire lock");
          return;
       }
-      // If we can't cancel the termination, release the lock, return and continue
+      // If we can't cancel the termination, release the lock, return and
+      // continue
       // with a transient conversation
       if (!longRunningConversations.get(cid).cancelTermination())
       {
          longRunningConversations.get(cid).unlock();
-         log.debug("Failed to cancel termination of conversation " + cid);
       }
       else
       {
@@ -153,8 +166,10 @@
          Future<?> terminationHandle = scheduleForTermination(cid);
          // When the conversation ends, a long-running conversation needs to
          // start its self-destruct. We can have the case where the conversation
-         // is a previously known conversation (that had it's termination canceled in the
-         // beginConversation) or the case where we have a completely new long-running conversation.
+         // is a previously known conversation (that had it's termination
+         // canceled in the
+         // beginConversation) or the case where we have a completely new
+         // long-running conversation.
          if (longRunningConversations.containsKey(currentConversation.getId()))
          {
             longRunningConversations.get(currentConversation.getId()).unlock();
@@ -165,7 +180,7 @@
             ConversationEntry conversationEntry = ConversationEntry.of(cid, terminationHandle);
             longRunningConversations.put(cid, conversationEntry);
          }
-         log.trace("Scheduling " + currentConversation + " for termination");
+         log.trace("Scheduled " + currentConversation + " for termination");
       }
       else
       {
@@ -175,10 +190,7 @@
          log.trace("Destroying transient conversation " + currentConversation);
          if (longRunningConversations.containsKey(cid))
          {
-            if (!longRunningConversations.get(cid).cancelTermination())
-            {
-               log.info("Failed to cancel termination of conversation " + cid);
-            }
+            longRunningConversations.get(cid).cancelTermination();
             longRunningConversations.get(cid).unlock();
          }
          ConversationContext.INSTANCE.destroy();
@@ -223,7 +235,7 @@
        */
       public void run()
       {
-         log.trace("Conversation " + cid + " timed out and was destroyed");
+         log.trace("Conversation " + cid + " timed out. Destroying it");
          longRunningConversations.remove(cid).destroy(session);
       }
    }

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/bindings/ConversationIdName.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/bindings/ConversationIdName.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/bindings/ConversationIdName.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.webbeans.conversation.bindings;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+/**
+ * The conversation id request parameter name
+ *  
+ * @author Nicklas Karlsson
+ */
+ at Target( { TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+ at BindingType
+public @interface ConversationIdName
+{
+}

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -0,0 +1,71 @@
+package org.jboss.webbeans.jsf;
+
+import javax.faces.component.html.HtmlInputHidden;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpSession;
+
+public class JSFHelper
+{
+   private static final String CONVERSATION_PROPAGATION_COMPONENT_ID = "webbeans_conversation_propagation";
+   private static final String CONVERSATION_ID_NAME = "cid";
+
+   public static boolean isPostback()
+   {
+      return FacesContext.getCurrentInstance().getRenderKit().getResponseStateManager().isPostback(FacesContext.getCurrentInstance());
+   }
+
+   public static void removePropagationComponent()
+   {
+      HtmlInputHidden propagationComponent = getPropagationComponent();
+      if (propagationComponent != null)
+      {
+         FacesContext.getCurrentInstance().getViewRoot().getChildren().remove(propagationComponent);
+      }
+   }
+
+   public static void createOrUpdatePropagationComponent(String cid)
+   {
+      HtmlInputHidden propagationComponent = getPropagationComponent();
+      if (propagationComponent == null)
+      {
+         propagationComponent = (HtmlInputHidden) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE);
+         propagationComponent.setId(CONVERSATION_PROPAGATION_COMPONENT_ID);
+         FacesContext.getCurrentInstance().getViewRoot().getChildren().add(propagationComponent);
+      }
+      propagationComponent.setValue(cid);
+   }
+
+   private static HtmlInputHidden getPropagationComponent()
+   {
+      return (HtmlInputHidden) FacesContext.getCurrentInstance().getViewRoot().findComponent(CONVERSATION_PROPAGATION_COMPONENT_ID);
+   }
+
+   private static String getConversationIdFromRequest()
+   {
+      return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(CONVERSATION_ID_NAME);
+   }
+
+   public static String getConversationIdFromPropagationComponent()
+   {
+      String cid = null;
+      HtmlInputHidden propagationComponent = getPropagationComponent();
+      if (propagationComponent != null)
+      {
+         cid = propagationComponent.getValue().toString();
+      }
+      return cid;
+   }
+
+   public static String getConversationId()
+   {
+      if (isPostback())
+      {
+         return getConversationIdFromPropagationComponent();
+      }
+      else
+      {
+         return getConversationIdFromRequest();
+      }
+   }
+
+}

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-02-12 23:03:39 UTC (rev 1502)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -17,9 +17,6 @@
 package org.jboss.webbeans.jsf;
 
 import javax.context.Conversation;
-import javax.faces.component.UIViewRoot;
-import javax.faces.component.html.HtmlInputHidden;
-import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
@@ -29,7 +26,6 @@
 import org.jboss.webbeans.conversation.ConversationManager;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * A phase listener for propagating conversation id over postbacks through a
@@ -43,112 +39,67 @@
    // The ID/name of the conversation-propagating component
    private static final String CONVERSATION_PROPAGATION_COMPONENT = "webbeans_conversation_propagation";
 
-   private static LogProvider log = Logging.getLogProvider(ServletLifecycle.class);
+   private static LogProvider log = Logging.getLogProvider(WebBeansPhaseListener.class);
 
-   /**
-    * Indicates if we are in a JSF postback or not
-    * 
-    * @return True if postback, false otherwise
-    */
-   private boolean isPostback()
+   public void beforePhase(PhaseEvent phaseEvent)
    {
-      return FacesContext.getCurrentInstance().getRenderKit().getResponseStateManager().isPostback(FacesContext.getCurrentInstance());
-   }
-
-   public void afterPhase(PhaseEvent phaseEvent)
-   {
-      // If we are restoring a view and we are in a postback
-      if (phaseEvent.getPhaseId().equals(PhaseId.RESTORE_VIEW) && isPostback())
+      if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
       {
-         log.trace("Processing after RESTORE_VIEW phase");
-         HtmlInputHidden propagationComponent = getPropagationComponent(phaseEvent.getFacesContext().getViewRoot());
-         // Resume the conversation if the propagation component can be found
-         if (propagationComponent != null)
-         {
-            log.trace("Propagation component found");
-            String cid = propagationComponent.getValue().toString();
-            ConversationManager conversationManager = CurrentManager.rootManager().getInstanceByType(ConversationManager.class);
-            conversationManager.beginOrRestoreConversation(cid);
-         }
+         beforeRenderReponse();
       }
-      else if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
+      else if (phaseEvent.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES))
       {
-         ConversationContext.INSTANCE.setActive(false);
+         beforeApplyRequestValues();
       }
-   }
+   }   
 
-   public void beforePhase(PhaseEvent phaseEvent)
+   private void beforeRenderReponse()
    {
-      if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE) && isPostback())
+      if (JSFHelper.isPostback())
       {
-         // If we are rendering the response from a postback
-         log.trace("Processing after RENDER_RESPONSE phase");
          Conversation conversation = CurrentManager.rootManager().getInstanceByType(Conversation.class);
-         // If we are in a long-running conversation, create or update the
-         // conversation id
-         // in the propagation component in the view root
          if (conversation.isLongRunning())
          {
-            log.trace("Updating propagation for " + conversation);
-            createOrUpdatePropagationComponent(phaseEvent.getFacesContext(), conversation.getId());
+            JSFHelper.createOrUpdatePropagationComponent(conversation.getId());
          }
          else
          {
-            // Otherwise, remove the component from the view root
-            log.trace("Removing propagation for " + conversation);
-            removePropagationComponent(phaseEvent.getFacesContext().getViewRoot());
+            JSFHelper.removePropagationComponent();
          }
+
       }
-      else if (phaseEvent.getPhaseId().equals(PhaseId.APPLY_REQUEST_VALUES))
-      {
-         ConversationContext.INSTANCE.setActive(true);
-      }
    }
-
-   /**
-    * Gets the conversation propagation component
-    * 
-    * @param viewRoot The view root to search in
-    * @return The component, or null if it's not present
-    */
-   private HtmlInputHidden getPropagationComponent(UIViewRoot viewRoot)
+   
+   private void beforeApplyRequestValues()
    {
-      return (HtmlInputHidden) viewRoot.findComponent(CONVERSATION_PROPAGATION_COMPONENT);
-   }
-
-   /**
-    * Creates or updates the conversation propagation component in the view root
-    * 
-    * @param facesContext The faces context
-    * @param cid The conversation id to propagate
-    */
-   private void createOrUpdatePropagationComponent(FacesContext facesContext, String cid)
+      ConversationContext.INSTANCE.setActive(true);
+   }   
+   
+   public void afterPhase(PhaseEvent phaseEvent)
    {
-      HtmlInputHidden propagationComponent = getPropagationComponent(facesContext.getViewRoot());
-      // Creates the component if it can't be found
-      if (propagationComponent == null)
+      if (phaseEvent.getPhaseId().equals(PhaseId.RESTORE_VIEW))
       {
-         propagationComponent = (HtmlInputHidden) facesContext.getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE);
-         propagationComponent.setId(CONVERSATION_PROPAGATION_COMPONENT);
-         facesContext.getViewRoot().getChildren().add(propagationComponent);
+         afterRestoreView();
       }
-      propagationComponent.setValue(cid);
-   }
-
-   /**
-    * Removes the conversation propagation from the view root (if present)
-    * 
-    * @param viewRoot The view root to remove the component from
-    */
-   private void removePropagationComponent(UIViewRoot viewRoot)
+      else if (phaseEvent.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
+      {
+         afterRenderResponse();
+      }
+   }   
+   
+   private void afterRestoreView()
    {
-      HtmlInputHidden propagationComponent = getPropagationComponent(viewRoot);
-      if (propagationComponent != null)
+      if (JSFHelper.isPostback())
       {
-         viewRoot.getChildren().remove(propagationComponent);
+         CurrentManager.rootManager().getInstanceByType(ConversationManager.class).beginOrRestoreConversation(JSFHelper.getConversationId());
       }
    }
 
+   private void afterRenderResponse()
+   {
+      ConversationContext.INSTANCE.setActive(false);
+   }
+
    public PhaseId getPhaseId()
    {
       return PhaseId.ANY_PHASE;

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java	2009-02-12 23:03:39 UTC (rev 1502)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java	2009-02-13 11:52:35 UTC (rev 1503)
@@ -18,13 +18,11 @@
 package org.jboss.webbeans.servlet;
 
 import javax.context.Conversation;
-import javax.context.SessionScoped;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
 import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.context.AbstractBeanMapContext;
 import org.jboss.webbeans.context.ApplicationContext;
 import org.jboss.webbeans.context.ConversationContext;
 import org.jboss.webbeans.context.DependentContext;




More information about the weld-commits mailing list