[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Fri Oct 27 08:58:09 EDT 2006


  User: gavin   
  Date: 06/10/27 08:58:09

  Modified:    src/main/org/jboss/seam/core     Manager.java Pageflow.java
                        Pages.java
  Added:       src/main/org/jboss/seam/core     FacesPage.java
  Log:
  use a component to persist page-scoped data
  change how page parameters are stored
  improve test harness
  
  Revision  Changes    Path
  1.105     +26 -43    jboss-seam/src/main/org/jboss/seam/core/Manager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Manager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -b -r1.104 -r1.105
  --- Manager.java	25 Oct 2006 21:21:03 -0000	1.104
  +++ Manager.java	27 Oct 2006 12:58:09 -0000	1.105
  @@ -19,6 +19,7 @@
   import javax.faces.context.ExternalContext;
   import javax.faces.context.FacesContext;
   import javax.faces.event.PhaseEvent;
  +import javax.faces.event.PhaseId;
   import javax.portlet.ActionResponse;
   import javax.servlet.http.HttpServletResponse;
   
  @@ -32,6 +33,7 @@
   import org.jboss.seam.annotations.Scope;
   import org.jboss.seam.contexts.ContextAdaptor;
   import org.jboss.seam.contexts.Contexts;
  +import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.contexts.ServerConversationContext;
   import org.jboss.seam.pageflow.Page;
   import org.jboss.seam.util.Id;
  @@ -41,7 +43,7 @@
    *
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.104 $
  + * @version $Revision: 1.105 $
    */
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.manager")
  @@ -50,10 +52,6 @@
   {
      private static final Log log = LogFactory.getLog(Manager.class);
   
  -   private static final String NAME = Seam.getComponentName(Manager.class);
  -   public static final String CONVERSATION_ID = NAME + ".conversationId";
  -   public static final String CONVERSATION_IS_LONG_RUNNING = NAME + ".conversationIsLongRunning";
  -
      //The id of the current conversation
      private String currentConversationId;
      private List<String> currentConversationIdStack;
  @@ -335,32 +333,13 @@
         //if the session is invalid, don't put the conversation id
         //in the view, 'cos we are expecting the conversation to
         //be destroyed by the servlet session listener
  -      if ( Contexts.isPageContextActive() ) 
  +      if ( Contexts.isPageContextActive() && Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE ) 
         {
            //TODO: we really only need to execute this code when we are in the 
            //      RENDER_RESPONSE phase, ie. not before redirects
  -         store();
  +         org.jboss.seam.core.FacesPage.instance().storeConversation();
         }
         writeConversationIdToResponse( response, getCurrentConversationId() );
  -      
  -      if ( Contexts.isPageContextActive() && Init.instance().isJbpmInstalled() )
  -      {
  -         Pageflow.instance().store();
  -      }
  -   }
  -
  -   private void store()
  -   {
  -      if ( isReallyLongRunningConversation() )
  -      {
  -         Contexts.getPageContext().set( CONVERSATION_ID, getCurrentConversationId() );
  -         Contexts.getPageContext().set( CONVERSATION_IS_LONG_RUNNING, true );
  -      }
  -      else
  -      {
  -         Contexts.getPageContext().remove(CONVERSATION_ID);
  -         Contexts.getPageContext().remove(CONVERSATION_IS_LONG_RUNNING);
  -      }
      }
   
      private void discardTemporaryConversation(ContextAdaptor session, Object response)
  @@ -374,17 +353,17 @@
         if ( stack.size()>1 )
         {
            String outerConversationId = stack.get(1);
  -         if ( Contexts.isPageContextActive() )
  +         if ( Contexts.isPageContextActive() && Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE  )
            {
  -            Contexts.getPageContext().set(CONVERSATION_ID, outerConversationId);
  +            org.jboss.seam.core.FacesPage.instance().discardNestedConversation(outerConversationId);
            }
            writeConversationIdToResponse(response, outerConversationId);
         }
         else
         {
  -         if ( Contexts.isPageContextActive() )
  +         if ( Contexts.isPageContextActive() && Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE  )
            {
  -            Contexts.getPageContext().remove(CONVERSATION_ID);
  +            org.jboss.seam.core.FacesPage.instance().discardTemporaryConversation();
            }
         }
   
  @@ -400,20 +379,22 @@
      {
         if (response instanceof HttpServletResponse)
         {
  -         ( (HttpServletResponse) response ).setHeader(conversationIdParameter, conversationId);
  +         ( (HttpServletResponse) response ).setHeader( getConversationIdParameter(), conversationId );
         }
         else if (response instanceof ActionResponse)
         {
  -         ( (ActionResponse) response ).setRenderParameter(conversationIdParameter, conversationId);
  +         ( (ActionResponse) response ).setRenderParameter( getConversationIdParameter(), conversationId );
         }
      }
   
  -   private void removeCurrentConversationAndDestroyNestedContexts(ContextAdaptor session) {
  +   private void removeCurrentConversationAndDestroyNestedContexts(ContextAdaptor session) 
  +   {
         ConversationEntries.instance().removeConversationEntry( getCurrentConversationId() );
         destroyNestedContexts( session, getCurrentConversationId() );
      }
   
  -   private void destroyNestedContexts(ContextAdaptor session, String conversationId) {
  +   private void destroyNestedContexts(ContextAdaptor session, String conversationId) 
  +   {
         List<ConversationEntry> entries = new ArrayList<ConversationEntry>( ConversationEntries.instance().getConversationEntries() );
         for  ( ConversationEntry ce: entries )
         {
  @@ -464,9 +445,10 @@
         {
            //if it is not passed as a request parameter,
            //try to get it from the page context
  -         storedConversationId = (String) Contexts.getPageContext().get(CONVERSATION_ID);
  -         isLongRunningConversation = (Boolean) Contexts.getPageContext().get(CONVERSATION_IS_LONG_RUNNING);
  -         if (isLongRunningConversation==null) isLongRunningConversation = false;
  +         org.jboss.seam.core.FacesPage page = org.jboss.seam.core.FacesPage.instance();
  +         storedConversationId = page.getConversationId();
  +         isLongRunningConversation = page.isConversationLongRunning();
  +         //if (isLongRunningConversation==null) isLongRunningConversation = false;
         }
   
         else if (storedConversationId!=null)
  @@ -974,8 +956,9 @@
         noConversation();
         
         //stuff from jPDL takes precedence
  -      String pageflowName = (String) Contexts.getPageContext().get(Pageflow.PAGEFLOW_NAME);
  -      String pageflowNodeName = (String) Contexts.getPageContext().get(Pageflow.PAGEFLOW_NODE_NAME);
  +      org.jboss.seam.core.FacesPage page = org.jboss.seam.core.FacesPage.instance();
  +      String pageflowName = page.getPageflowName();
  +      String pageflowNodeName = page.getPageflowNodeName();
         
         String noConversationViewId = null;
         if (pageflowName==null || pageflowNodeName==null)
  
  
  
  1.37      +4 -30     jboss-seam/src/main/org/jboss/seam/core/Pageflow.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Pageflow.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pageflow.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -b -r1.36 -r1.37
  --- Pageflow.java	25 Oct 2006 21:18:55 -0000	1.36
  +++ Pageflow.java	27 Oct 2006 12:58:09 -0000	1.37
  @@ -12,7 +12,6 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.seam.Component;
   import org.jboss.seam.ScopeType;
  -import org.jboss.seam.Seam;
   import org.jboss.seam.annotations.Intercept;
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Scope;
  @@ -35,11 +34,6 @@
   @Intercept(NEVER)
   public class Pageflow extends AbstractMutable implements Serializable
   {
  -   private static final String NAME = Seam.getComponentName(Pageflow.class);
  -   public static final String PAGEFLOW_COUNTER = NAME + ".counter";
  -   public static final String PAGEFLOW_NODE_NAME = NAME + ".nodeName";
  -   public static final String PAGEFLOW_NAME = NAME + ".name";
  -
      private static final Log log = LogFactory.getLog(Pageflow.class);
      
      private int counter;
  @@ -78,9 +72,9 @@
      {
         if ( processInstance!=null )
         {
  -         
  -         String pageflowName = (String) Contexts.getPageContext().get(PAGEFLOW_NAME);
  -         String pageflowNodeName = (String) Contexts.getPageContext().get(PAGEFLOW_NODE_NAME);
  +         org.jboss.seam.core.FacesPage page = org.jboss.seam.core.FacesPage.instance();
  +         String pageflowName = page.getPageflowName();
  +         String pageflowNodeName = page.getPageflowNodeName();
            boolean canReposition = getPage().isBackEnabled() && 
                  processInstance.getProcessDefinition().getName().equals(pageflowName) && //probably not necessary
                  pageflowNodeName!=null; //probably not necessary
  @@ -96,8 +90,7 @@
            else
            {
               //check the counter to detect illegal use of backbutton
  -            //Integer counter = (Integer) attributes.get(Manager.PAGEFLOW_COUNTER);
  -            Integer pageCounter = (Integer) Contexts.getPageContext().get(PAGEFLOW_COUNTER);
  +            Integer pageCounter = org.jboss.seam.core.FacesPage.instance().getPageflowCounter();
               if ( pageCounter!=null && getPageflowCounter()!=pageCounter )
               {
                  illegalNavigationError();
  @@ -283,23 +276,4 @@
         return "Pageflow(" + name + ")";
      }
   
  -   /**
  -    * Store the current pageflow state in the page context
  -    */
  -   public void store()
  -   {
  -      if ( isInProcess() )
  -      {
  -         Contexts.getPageContext().set( PAGEFLOW_NAME, getProcessInstance().getProcessDefinition().getName() );
  -         Contexts.getPageContext().set( PAGEFLOW_NODE_NAME, getNode().getName() );
  -         Contexts.getPageContext().set( PAGEFLOW_COUNTER, getPageflowCounter() );
  -      }
  -      else
  -      {
  -         Contexts.getPageContext().remove(PAGEFLOW_NAME);
  -         Contexts.getPageContext().remove(PAGEFLOW_NODE_NAME);
  -         Contexts.getPageContext().remove(PAGEFLOW_COUNTER);
  -      }
  -   }
  -
   }
  
  
  
  1.37      +10 -21    jboss-seam/src/main/org/jboss/seam/core/Pages.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Pages.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pages.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -b -r1.36 -r1.37
  --- Pages.java	25 Oct 2006 15:14:35 -0000	1.36
  +++ Pages.java	27 Oct 2006 12:58:09 -0000	1.37
  @@ -411,20 +411,14 @@
      {
         String viewId = facesContext.getViewRoot().getViewId();
         
  -      Map<String, Object> pageParameters = (Map<String, Object>) Contexts.getPageContext().get(PAGE_PARAMETERS);
  -      if (pageParameters!=null)
  -      {
  -      
            for (PageParameter pageParameter: getPage(viewId).pageParameters)
            {         
  -            Object object = pageParameters.get(pageParameter.name);
  +         Object object = Contexts.getPageContext().get(pageParameter.name);
               if (object!=null)
               {
                  pageParameter.valueBinding.setValue(object);
               }
            }
  -      
  -      }
      }
   
      public String getNoConversationViewId()
  @@ -458,14 +452,9 @@
         String viewId = facesContext.getViewRoot().getViewId();
         if (viewId!=null)
         {
  -         Map<String, Object> parameters = getParameters(viewId);
  -         if ( parameters.isEmpty() )
  -         {
  -            Contexts.getPageContext().remove(PAGE_PARAMETERS);
  -         }
  -         else
  +        for ( Map.Entry<String, Object> param: getParameters(viewId).entrySet() )
            {
  -            Contexts.getPageContext().set(PAGE_PARAMETERS, parameters);
  +           Contexts.getPageContext().set( param.getKey(), param.getValue() );
            }
         }
      }
  
  
  
  1.1      date: 2006/10/27 12:58:09;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/core/FacesPage.java
  
  Index: FacesPage.java
  ===================================================================
  package org.jboss.seam.core;
  
  import java.io.Serializable;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.InterceptionType;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Intercept;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.contexts.Contexts;
  
  /**
   * Book-keeping component that persists information
   * about the conversation associated with the current
   * page.
   * 
   * @author Gavin King
   *
   */
  @Name("org.jboss.seam.core.facesPage")
  @Intercept(InterceptionType.NEVER)
  @Scope(ScopeType.PAGE)
  public class FacesPage implements Serializable
  {
     private String pageflowName;
     private Integer pageflowCounter;
     private String pageflowNodeName;
     
     private String conversationId;
     private boolean conversationIsLongRunning;
     
     //private Map<String, Object> pageParameters;
     
     public String getConversationId()
     {
        return conversationId;
     }
     
     public void discardTemporaryConversation()
     {
        conversationId = null;
        conversationIsLongRunning = false;
     }
     
     public void discardNestedConversation(String outerConversationId)
     {
        conversationId = outerConversationId;
        conversationIsLongRunning = true;
     }
     
     public void storeConversation()
     {
        Manager manager = Manager.instance();
        if ( manager.isReallyLongRunningConversation() )
        {
           conversationId = manager.getCurrentConversationId();
           conversationIsLongRunning = true;
        }
        else
        {
           conversationId = null;
           conversationIsLongRunning = false;
        }
        
        if ( Init.instance().isJbpmInstalled() )
        {
           Pageflow pageflow = Pageflow.instance();
           if ( pageflow.isInProcess() )
           {
              pageflowName = pageflow.getProcessInstance().getProcessDefinition().getName();
              pageflowNodeName = pageflow.getNode().getName();
              pageflowCounter = pageflow.getPageflowCounter();
           }
           else
           {
              pageflowName = null;
              pageflowNodeName = null;
              pageflowCounter = null;
           }
        }
     }
     
     public static FacesPage instance()
     {
        if ( !Contexts.isPageContextActive() )
        {
           throw new IllegalStateException("No page context active");
        }
        return (FacesPage) Component.getInstance(FacesPage.class, ScopeType.PAGE, true);
     }
  
     public boolean isConversationLongRunning()
     {
        return conversationIsLongRunning;
     }
  
     public Integer getPageflowCounter()
     {
        return pageflowCounter;
     }
  
     public String getPageflowName()
     {
        return pageflowName;
     }
  
     public String getPageflowNodeName()
     {
        return pageflowNodeName;
     }
  
     /*public Map<String, Object> getPageParameters()
     {
        return pageParameters==null ? Collections.EMPTY_MAP : pageParameters;
     }
  
     public void setPageParameters(Map<String, Object> pageParameters)
     {
        this.pageParameters = pageParameters.isEmpty() ? null : pageParameters;
     }
     
     /**
      * Used by test harness
      * 
      * @param name the page parameter name
      * @param value the value
      */
     /*public void setPageParameter(String name, Object value)
     {
        if (pageParameters==null)
        {
           pageParameters = new HashMap<String, Object>();
        }
        pageParameters.put(name, value);
     }*/
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list