taylor      2004/10/13 17:20:15

  Modified:    portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces
                        FacesContextFactoryImpl.java
                        PortletViewHandlerImpl.java
                        PortletFacesContextImpl.java FacesPortlet.java
  Log:
  The JSF Bridge now  retains internal JSF nav state amongst views even when you 
navigate via jetspeed to other pages or tabs and back
  The Tree View, Data View, and Panel components all seem to be keeping state 
correctly now
  
  Revision  Changes    Path
  1.3       +12 -4     
jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/FacesContextFactoryImpl.java
  
  Index: FacesContextFactoryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/FacesContextFactoryImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FacesContextFactoryImpl.java      11 Sep 2004 18:43:26 -0000      1.2
  +++ FacesContextFactoryImpl.java      14 Oct 2004 00:20:15 -0000      1.3
  @@ -20,6 +20,7 @@
   import javax.faces.context.FacesContextFactory;
   import javax.faces.lifecycle.Lifecycle;
   
  +import javax.portlet.PortletConfig;
   import javax.portlet.PortletContext;
   import javax.portlet.PortletRequest;
   import javax.portlet.PortletResponse;
  @@ -37,17 +38,24 @@
        * @see 
javax.faces.context.FacesContextFactory#getFacesContext(java.lang.Object,
        *      java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)
        */
  -    public FacesContext getFacesContext(Object context, Object request, Object 
response, Lifecycle lifecycle)
  +    public FacesContext getFacesContext(Object config, Object request, Object 
response, Lifecycle lifecycle) 
               throws FacesException
       {
  -        if (context instanceof PortletContext)
  +        if (config instanceof PortletConfig)
           {
  -            return new PortletFacesContextImpl((PortletContext) context, 
(PortletRequest) request,
  +            PortletConfig pc = (PortletConfig)config;
  +            PortletContext context = pc.getPortletContext();
  +            PortletFacesContextImpl facesContext = new PortletFacesContextImpl( 
  +                    (PortletContext) context,  
  +                    (PortletRequest) request,
                       (PortletResponse) response);
  +            String defaultViewName = 
pc.getInitParameter(FacesPortlet.PARAM_VIEW_PAGE);            
  +            // facesContext.resolveViewRoot(defaultViewName, 
(PortletRequest)request);
  +            return facesContext;
           }
           else
           {
  -            throw new FacesException("Unsupported context type " + 
context.getClass().getName());
  +            throw new FacesException("Unsupported context type " + 
config.getClass().getName());
           }
       }
   }
  
  
  
  1.3       +18 -2     
jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletViewHandlerImpl.java
  
  Index: PortletViewHandlerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletViewHandlerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PortletViewHandlerImpl.java       11 Sep 2004 18:43:26 -0000      1.2
  +++ PortletViewHandlerImpl.java       14 Oct 2004 00:20:15 -0000      1.3
  @@ -82,7 +82,15 @@
        */
       public UIViewRoot createView(FacesContext facesContext, String viewId)
       {
  -        return handler.createView(facesContext, viewId);
  +        System.out.println("Creating view: " + viewId);        
  +        
  +        UIViewRoot root = handler.createView(facesContext, viewId);
  +        if (root != null)
  +        {
  +            facesContext.setViewRoot(root);
  +        }
  +        
  +        return root;
       }
   
       /**
  @@ -116,6 +124,7 @@
        */
       public void renderView(FacesContext facesContext, UIViewRoot viewToRender) 
throws IOException, FacesException
       {
  +        System.out.println("Rendering view: " + viewToRender);
           handler.renderView(facesContext, viewToRender);
       }
   
  @@ -125,7 +134,14 @@
        */
       public UIViewRoot restoreView(FacesContext facesContext, String viewId)
       {
  -        return handler.restoreView(facesContext, viewId);
  +        System.out.println("restoring view: " + viewId);        
  +        UIViewRoot root = handler.restoreView(facesContext, viewId);
  +        if (root != null)
  +        {
  +            facesContext.setViewRoot(root);
  +        }
  +        // System.out.println("Rendering view root: " + root);
  +        return root;
       }
   
       /**
  
  
  
  1.3       +52 -2     
jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletFacesContextImpl.java
  
  Index: PortletFacesContextImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/PortletFacesContextImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PortletFacesContextImpl.java      11 Sep 2004 18:43:26 -0000      1.2
  +++ PortletFacesContextImpl.java      14 Oct 2004 00:20:15 -0000      1.3
  @@ -33,9 +33,12 @@
   import javax.faces.render.RenderKit;
   import javax.faces.render.RenderKitFactory;
   
  +import javax.portlet.ActionRequest;
  +import javax.portlet.PortletConfig;
   import javax.portlet.PortletContext;
   import javax.portlet.PortletRequest;
   import javax.portlet.PortletResponse;
  +import javax.portlet.PortletSession;
   
   import net.sourceforge.myfaces.util.NullIterator;
   
  @@ -88,13 +91,17 @@
       /** The render kit factory. */
       private RenderKitFactory renderKitFactory;
   
  +    /** The JSF_VIEW_ID used to maintain the state of the view action. */
  +    public static final String JSF_VIEW_ID = "jsf_viewid";
  +    
       /**
        * @param portletContext The [EMAIL PROTECTED] PortletContext}.
        * @param portletRequest The [EMAIL PROTECTED] PortletRequest}.
        * @param portletResponse The [EMAIL PROTECTED] PortletResponse}.
        */
  -    public PortletFacesContextImpl(PortletContext portletContext, PortletRequest 
portletRequest,
  -            PortletResponse portletResponse)
  +    public PortletFacesContextImpl(PortletContext portletContext,                   
                 
  +                                   PortletRequest portletRequest,
  +                                   PortletResponse portletResponse)
       {
           this.application = ((ApplicationFactory) 
FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY))
                   .getApplication();
  @@ -102,6 +109,49 @@
           this.externalContext = new PortletExternalContextImpl(portletContext, 
portletRequest, portletResponse);
           FacesContext.setCurrentInstance(this); //protected method, therefore
                                                  // must be called from here
  +    }
  +    
  +    public UIViewRoot resolveViewRoot(String defaultViewName, PortletRequest 
portletRequest)
  +    {
  +System.out.println("-----------------------------------------");        
  +System.out.println("+++ Resolving view root: DEFAULT VID: " + defaultViewName);     
   
  +        // shoot: can't get the entity id and be portable
  +        PortletRequest request = (PortletRequest)externalContext.getRequest();
  +        String viewId = request.getParameter(JSF_VIEW_ID);
  +System.out.println("+++ Resolving: END VIEW ID: " + viewId);                
  +        if (viewId == null)
  +        {
  +            viewId = defaultViewName;
  +        }
  +System.out.println("+++ Resolving: END VIEW ID: " + viewId);        
  +        
  +    if (portletRequest instanceof ActionRequest)
  +    {
  +        System.out.println("+++ Resolving: ACTION: " + viewId);
  +        setViewRoot(viewRoot);        
  +        portletRequest.setAttribute(FacesPortlet.REQUEST_SERVLET_PATH, 
viewId.replaceAll(".jsp", ".jsf"));        
  +        return null;
  +    }
  +
  +
  +        UIViewRoot viewRoot = 
  +            (UIViewRoot)request.getPortletSession().getAttribute(viewId, 
PortletSession.PORTLET_SCOPE);
  +        if (null == viewRoot)
  +        {
  +System.out.println("+++ Resolving: CREATING NEW VIEW ROOT: " + viewId);             
       
  +            viewRoot = application.getViewHandler().createView(this, viewId);
  +            //viewRoot = new UIViewRoot();
  +            viewRoot.setViewId(viewId);
  +            viewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
  +            request.getPortletSession().setAttribute(viewId, viewRoot, 
PortletSession.PORTLET_SCOPE);
  +        }
  +        else
  +        {
  +System.out.println("+++ Resolving: USING FROM SESSION VIEW ROOT: " + viewId);       
                         
  +        }
  +        setViewRoot(viewRoot);
  +        portletRequest.setAttribute(FacesPortlet.REQUEST_SERVLET_PATH, 
viewId.replaceAll(".jsp", ".jsf"));
  +        return viewRoot;
       }
   
       /**
  
  
  
  1.6       +77 -13    
jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/FacesPortlet.java
  
  Index: FacesPortlet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/portals-bridges/myfaces/src/java/org/apache/portals/bridges/myfaces/FacesPortlet.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FacesPortlet.java 16 Sep 2004 23:44:52 -0000      1.5
  +++ FacesPortlet.java 14 Oct 2004 00:20:15 -0000      1.6
  @@ -35,6 +35,7 @@
   import javax.portlet.PortletException;
   import javax.portlet.PortletRequest;
   import javax.portlet.PortletResponse;
  +import javax.portlet.PortletSession;
   import javax.portlet.RenderRequest;
   import javax.portlet.RenderResponse;
   
  @@ -47,7 +48,8 @@
    * portlet environment.
    * </p>
    * 
  - * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat </a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
    */
   public class FacesPortlet extends GenericPortlet
   {
  @@ -384,9 +386,11 @@
               log.trace("Begin FacesPortlet.processAction()");
           }
   
  +        
           // Acquire the FacesContext instance for this request
  -        FacesContext context = 
getFacesContextFactory().getFacesContext(portletConfig.getPortletContext(), request,
  -                response, getLifecycle());
  +        FacesContext context = getFacesContextFactory().getFacesContext(
  +                portletConfig, 
  +                request, response, getLifecycle());
   
           // Restore view if available.
           setDefaultView(context, defaultPage);
  @@ -406,11 +410,20 @@
                       log.trace("End Executing phases");
                   }
                   // The view should have been restore.
  -                // Pass it to the render request.
  -                request.getPortletSession().setAttribute(VIEW_ROOT, 
context.getViewRoot());
  +                // Pass it to the render request. 
  +                                
  +                request.getPortletSession().setAttribute(createViewRootKey(context, 
defaultPage), context.getViewRoot());
  +                ActionResponse actionResponse = (ActionResponse)response;
  +                                
  +                // actionResponse.setRenderParameter(JSF_VIEW_ID, 
context.getViewRoot().getViewId()); // get the navigation change
  +                request.getPortletSession().setAttribute(JSF_VIEW_ID, 
context.getViewRoot().getViewId(), PortletSession.PORTLET_SCOPE);
               }
               else if (renderRequest)
  -            { 
  +            {
  +                //    getLifecycle().execute(context);
  +                String vi = context.getViewRoot().getViewId();
  +                context.getApplication().getViewHandler().restoreView(context, vi);
  +                
                   getLifecycle().render(context);
                   if (log.isTraceEnabled())
                   {
  @@ -456,6 +469,30 @@
           }
       }
   
  +    private String createViewRootKey(FacesContext context, String defaultView)
  +    {
  +        PortletRequest portletRequest = (PortletRequest) 
context.getExternalContext().getRequest();
  +        // String view = portletRequest.getParameter(JSF_VIEW_ID);
  +        String view = 
(String)portletRequest.getPortletSession().getAttribute(JSF_VIEW_ID, 
PortletSession.PORTLET_SCOPE);
  +        
  +        if (view == null)
  +        {
  +            view = defaultView;
  +        }
  +        String key = VIEW_ROOT + ":" + getPortletName();
  +        UIViewRoot root = context.getViewRoot();
  +        if (root != null)
  +        {
  +           key = key + ":" + root.getViewId();
  +        }
  +        else
  +        {
  +            key = key + ":" + view;
  +        }
  +        System.out.println("KEY [" + key + "]");
  +        return key;
  +    }
  +    
       /**
        * <p>
        * Set the view identifier to the view for the page to be rendered.
  @@ -472,32 +509,59 @@
           PortletRequest portletRequest = (PortletRequest) 
facesContext.getExternalContext().getRequest();
           if (portletRequest instanceof ActionRequest)
           {
  +            String view = 
(String)portletRequest.getPortletSession().getAttribute(JSF_VIEW_ID, 
PortletSession.PORTLET_SCOPE);
  +            
               if ((null != facesContext.getViewRoot()) && (null != 
facesContext.getViewRoot().getViewId()))
               {
                   defaultView = facesContext.getViewRoot().getViewId();
               }
  -            else if (null != portletRequest.getParameter(JSF_VIEW_ID))
  +            //else if (null != portletRequest.getParameter(JSF_VIEW_ID))
  +            else if (null != view)
               {
  -                defaultView = portletRequest.getParameter(JSF_VIEW_ID);
  +                //defaultView = portletRequest.getParameter(JSF_VIEW_ID);
  +                defaultView = view;
  +            }
  +            
  +            UIViewRoot viewRoot = (UIViewRoot)portletRequest.
  +                                    getPortletSession().
  +                                    getAttribute(createViewRootKey(facesContext, 
defaultView));
  +            if (viewRoot != null)
  +            {
  +                facesContext.setViewRoot(viewRoot);
  +                defaultView = facesContext.getViewRoot().getViewId();
               }
  +            
  +            portletRequest.setAttribute(REQUEST_SERVLET_PATH, 
defaultView.replaceAll(".jsp", ".jsf"));
           }
           else if (portletRequest instanceof RenderRequest)
           {
  +            // String view = portletRequest.getParameter(JSF_VIEW_ID);
  +            String view = 
(String)portletRequest.getPortletSession().getAttribute(JSF_VIEW_ID, 
PortletSession.PORTLET_SCOPE);
  +            
               if (null == facesContext.getViewRoot())
  -            {
  -                if (null != 
portletRequest.getPortletSession().getAttribute(VIEW_ROOT))
  +            {                
  +                if (view == null)
  +                {
  +                    view = defaultView;
  +                }
  +                UIViewRoot viewRoot = (UIViewRoot)portletRequest.
  +                                        getPortletSession().
  +                                        
getAttribute(createViewRootKey(facesContext, view));
  +                if (null != viewRoot)
                   {
  -                    facesContext.setViewRoot((UIViewRoot) 
portletRequest.getPortletSession().getAttribute(VIEW_ROOT));
  +                    facesContext.setViewRoot(viewRoot);
                       defaultView = facesContext.getViewRoot().getViewId();
                   }
                   else
                   {
                       facesContext.setViewRoot(new UIViewRoot());
  -                    facesContext.getViewRoot().setViewId(defaultView);
  +                    facesContext.getViewRoot().setViewId(view);
                       
facesContext.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
  +                    
portletRequest.getPortletSession().setAttribute(createViewRootKey(facesContext, view), 
viewRoot);
                   }                    
               }
  +            portletRequest.setAttribute(REQUEST_SERVLET_PATH, 
view.replaceAll(".jsp", ".jsf"));
           }
  -        portletRequest.setAttribute(REQUEST_SERVLET_PATH, 
defaultView.replaceAll(".jsp", ".jsf"));
  +        
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to