You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2005/02/10 21:24:17 UTC

cvs commit: incubator-myfaces/src/myfaces/org/apache/myfaces/application/jsp JspViewHandlerImpl.java

matzew      2005/02/10 12:24:17

  Modified:    src/myfaces/org/apache/myfaces/lifecycle LifecycleImpl.java
               src/myfaces/org/apache/myfaces/portlet
                        MyFacesGenericPortlet.java
               src/myfaces/org/apache/myfaces/application/jsp
                        JspViewHandlerImpl.java
  Added:       src/myfaces/org/apache/myfaces/portlet PortletUtil.java
  Log:
  closed MYFACES-101 in Jira; Thanks to Stan Silvert (JBoss Group)
  
  Revision  Changes    Path
  1.44      +12 -12    incubator-myfaces/src/myfaces/org/apache/myfaces/lifecycle/LifecycleImpl.java
  
  Index: LifecycleImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/lifecycle/LifecycleImpl.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- LifecycleImpl.java	27 Jan 2005 02:38:43 -0000	1.43
  +++ LifecycleImpl.java	10 Feb 2005 20:24:17 -0000	1.44
  @@ -40,12 +40,16 @@
   import java.util.List;
   import javax.portlet.PortletRequest;
   import org.apache.myfaces.portlet.MyFacesGenericPortlet;
  +import org.apache.myfaces.portlet.PortletUtil;
   
   /**
    * Implements the lifecycle as described in Spec. 1.0 PFD Chapter 2
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.44  2005/02/10 20:24:17  matzew
  + * closed MYFACES-101 in Jira; Thanks to Stan Silvert (JBoss Group)
  + *
    * Revision 1.43  2005/01/27 02:38:43  svieujot
    * Remove portlet-api dependency while keeping portlet support.
    *
  @@ -314,17 +318,13 @@
       private static String deriveViewId(FacesContext facesContext)
       {
           ExternalContext externalContext = facesContext.getExternalContext();
  -
  -        try{
  -            if (externalContext.getRequest() instanceof PortletRequest)
  -            {
  -                PortletRequest request = (PortletRequest)externalContext.getRequest();
  -                return request.getParameter(MyFacesGenericPortlet.VIEW_ID);
  -            }
  -        }catch(NoClassDefFoundError exception){
  -            // Portlet api jar isn't in the classpath.
  -        }
           
  +        if (PortletUtil.isPortletRequest(facesContext))
  +        {
  +            PortletRequest request = (PortletRequest)externalContext.getRequest();
  +            return request.getParameter(MyFacesGenericPortlet.VIEW_ID);
  +        }
  +
           String viewId = externalContext.getRequestPathInfo();  //getPathInfo
           if (viewId == null)
           {
  
  
  
  1.2       +20 -3     incubator-myfaces/src/myfaces/org/apache/myfaces/portlet/MyFacesGenericPortlet.java
  
  Index: MyFacesGenericPortlet.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/portlet/MyFacesGenericPortlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MyFacesGenericPortlet.java	26 Jan 2005 17:03:10 -0000	1.1
  +++ MyFacesGenericPortlet.java	10 Feb 2005 20:24:17 -0000	1.2
  @@ -54,6 +54,9 @@
    * @author  Stan Silvert (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.2  2005/02/10 20:24:17  matzew
  + * closed MYFACES-101 in Jira; Thanks to Stan Silvert (JBoss Group)
  + *
    * Revision 1.1  2005/01/26 17:03:10  matzew
    * MYFACES-86. portlet support provided by Stan Silver (JBoss Group)
    *
  @@ -66,6 +69,10 @@
       public static final String VIEW_ID =
           MyFacesGenericPortlet.class.getName() + ".VIEW_ID";
       
  +    // Signifies to MyFaces that the request is coming from a portlet.
  +    public static final String PORTLET_REQUEST_FLAG = 
  +        MyFacesGenericPortlet.class.getName() + ".PORTLET_REQUEST_FLAG";
  +    
       // PortletSession attribute
       private static final String CURRENT_FACES_CONTEXT = 
           MyFacesGenericPortlet.class.getName() + ".CURRENT_FACES_CONTEXT";
  @@ -198,6 +205,8 @@
           
           if (sessionTimedOut(request)) return;
           
  +        setPortletRequestFlag(request);
  +        
           FacesContext facesContext = facesContext(request, response);
                   
           try
  @@ -319,6 +328,11 @@
           return request.getPortletSession(false) == null;
       }
       
  +    private void setPortletRequestFlag(PortletRequest request)
  +    {
  +        request.getPortletSession().setAttribute(PORTLET_REQUEST_FLAG, "true");
  +    }
  +    
       /**
        * Render a JSF view.
        */
  @@ -332,10 +346,13 @@
           String viewId = request.getParameter(VIEW_ID);
           if ((viewId == null) || sessionTimedOut(request))
           {
  +            setPortletRequestFlag(request);
               nonFacesRequest(request,  response);
               return;
           }
          
  +        setPortletRequestFlag(request);
  +        
           try
           {
               ServletFacesContextImpl facesContext = (ServletFacesContextImpl)request.
  
  
  
  1.1                  incubator-myfaces/src/myfaces/org/apache/myfaces/portlet/PortletUtil.java
  
  Index: PortletUtil.java
  ===================================================================
  /*
   * Copyright 2005 The Apache Software Foundation.
   * 
   * 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.apache.myfaces.portlet;
  
  import javax.faces.context.FacesContext;
  import javax.portlet.RenderResponse;
  
  /**
   * Static utility class for portlet-related operations.
   *
   * @author  Stan Silvert
   */
  public final class PortletUtil 
  {
      
      /** Don't allow a new instance of PortletUtil */
      private PortletUtil() 
      {
      }
      
      public static boolean isRenderResponse(FacesContext facesContext)
      {
          if (!isPortletRequest(facesContext)) return false;
          
          return facesContext.getExternalContext().getResponse() instanceof RenderResponse;
      }
      
      public static boolean isPortletRequest(FacesContext facesContext)
      {
          return facesContext.getExternalContext()
                             .getSessionMap()
                             .get(MyFacesGenericPortlet.PORTLET_REQUEST_FLAG) != null;
      }
  }
  
  
  1.33      +19 -28    incubator-myfaces/src/myfaces/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
  
  Index: JspViewHandlerImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- JspViewHandlerImpl.java	27 Jan 2005 02:38:44 -0000	1.32
  +++ JspViewHandlerImpl.java	10 Feb 2005 20:24:17 -0000	1.33
  @@ -40,11 +40,15 @@
   import javax.portlet.PortletURL;
   import javax.portlet.RenderResponse;
   import org.apache.myfaces.portlet.MyFacesGenericPortlet;
  +import org.apache.myfaces.portlet.PortletUtil;
   
   /**
    * @author Thomas Spiegl (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.33  2005/02/10 20:24:17  matzew
  + * closed MYFACES-101 in Jira; Thanks to Stan Silvert (JBoss Group)
  + *
    * Revision 1.32  2005/01/27 02:38:44  svieujot
    * Remove portlet-api dependency while keeping portlet support.
    *
  @@ -184,16 +188,12 @@
   
       public String getActionURL(FacesContext facesContext, String viewId)
       {
  -        try{
  -            if (facesContext.getExternalContext().getResponse() instanceof RenderResponse)
  -            {
  -                RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();
  -                PortletURL url = response.createActionURL();
  -                url.setParameter(MyFacesGenericPortlet.VIEW_ID, viewId);
  -                return url.toString();
  -            }
  -        }catch(NoClassDefFoundError exception){
  -            // Portlet api jar isn't in the classpath.
  +        if (PortletUtil.isRenderResponse(facesContext))
  +        {
  +            RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();
  +            PortletURL url = response.createActionURL();
  +            url.setParameter(MyFacesGenericPortlet.VIEW_ID, viewId);
  +            return url.toString();
           }
           
           String path = getViewIdPath(facesContext, viewId);
  @@ -232,13 +232,9 @@
   
           String viewId = facesContext.getViewRoot().getViewId();
   
  -        try{
  -            if (externalContext.getRequest() instanceof PortletRequest) {
  -                externalContext.dispatch(viewId);
  -                return;
  -            }
  -        }catch(NoClassDefFoundError exception){
  -            // Portlet api jar isn't in the classpath.
  +        if (PortletUtil.isPortletRequest(facesContext)) {
  +            externalContext.dispatch(viewId);
  +            return;
           }
           
           ServletMapping servletMapping = getServletMapping(externalContext);
  @@ -330,17 +326,12 @@
               throw new IllegalArgumentException("ViewId must start with '/' (viewId = " + viewId + ")");
           }
   
  -        ExternalContext externalContext = facescontext.getExternalContext();
  -        
  -        try{
  -            if (externalContext.getRequest() instanceof PortletRequest) {
  -                return viewId;
  -            }
  -        }catch(NoClassDefFoundError exception){
  -            // Portlet api jar isn't in the classpath.
  +        if (PortletUtil.isPortletRequest(facescontext)) 
  +        {
  +            return viewId;
           }
           
  -        ServletMapping servletMapping = getServletMapping(externalContext);
  +        ServletMapping servletMapping = getServletMapping(facescontext.getExternalContext());
   
           if (servletMapping.isExtensionMapping())
           {