You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mf...@apache.org on 2009/01/15 21:49:33 UTC

svn commit: r734815 - in /myfaces/portlet-bridge/core/trunk_2.0.x: ./ api/src/main/java/javax/portlet/faces/ api/src/main/java/javax/portlet/faces/component/ api/src/main/resources/META-INF/ impl/src/main/java/org/apache/myfaces/portlet/faces/applicati...

Author: mfreedman
Date: Thu Jan 15 12:49:33 2009
New Revision: 734815

URL: http://svn.apache.org/viewvc?rev=734815&view=rev
Log:
Updated Notice files to be consistent.  Modified impl of PortletNamingContainerUIViewRoot to save/restore the namespace in a component attribute.  Modified PortletViewHandlerImpl to use PortletNamingContainerUIViewRoot by setting its as the componentType before delegating in createView.

Removed:
    myfaces/portlet-bridge/core/trunk_2.0.x/LICENSE.txt
    myfaces/portlet-bridge/core/trunk_2.0.x/NOTICE.txt
Modified:
    myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
    myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java
    myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/resources/META-INF/NOTICE
    myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletViewHandlerImpl.java
    myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/resources/META-INF/NOTICE

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java?rev=734815&r1=734814&r2=734815&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/GenericFacesPortlet.java Thu Jan 15 12:49:33 2009
@@ -200,6 +200,8 @@
       mFacesBridgeClass = null;
     }
     mDefaultViewIdMap = null;
+    
+    super.destroy();
   }
 
   /**

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java?rev=734815&r1=734814&r2=734815&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/java/javax/portlet/faces/component/PortletNamingContainerUIViewRoot.java Thu Jan 15 12:49:33 2009
@@ -10,13 +10,34 @@
  */
 package javax.portlet.faces.component;
 
+import java.io.IOException;
 import java.io.Serializable;
 
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+
+import java.util.Map;
+
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+
+import javax.faces.FacesException;
 import javax.faces.context.FacesContext;
+import javax.faces.component.ContextCallback;
 import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
+import javax.faces.el.ValueBinding;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+import javax.faces.event.PhaseListener;
+import javax.faces.render.Renderer;
 
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeUtil;
 import javax.portlet.faces.annotation.PortletNamingContainer;
 
 /**
@@ -32,72 +53,59 @@
 
   //TODO: This should be regenerated each time this is modified.  Can this be added to maven?
   private static final long   serialVersionUID = -4524288011655837711L;
-  private static final String SEPARATOR        = (new Character(NamingContainer.SEPARATOR_CHAR))
-                                                                                                .toString();
+  private static final String PORTLET_NAMESPACE_ID = Bridge.BRIDGE_PACKAGE_PREFIX + "PortletNamespaceId";
+  
+  private String mNamespace;
 
   public PortletNamingContainerUIViewRoot()
   {
     super();
   }
 
-  public PortletNamingContainerUIViewRoot(UIViewRoot viewRootToReplace)
-  {
-    super();
-    setViewId(viewRootToReplace.getViewId());
-    setLocale(viewRootToReplace.getLocale());
-    setRenderKitId(viewRootToReplace.getRenderKitId());
-  }
-
   /**
-   * Static method that implements NamingContainer semantics.  Ensures that the
-   * returned identifier contains the consumer (portal) provided unique portlet id.
-   * This ensures that those components in this NamingContainer generate ids which
-   * will not collide in the consumer page.<p>
-   * This method is provided for existing <code>UIViewRoot</code> implementations
-   * that prefer not to subclass <code>PortletNamingContainerUIViewRoot</code>
+   * Implements NamingContainer semantics.  Ensures that the returned identifier
+   * contains the consumer (portal) provided unique portlet id.  This ensures that
+   * those components in this NamingContainer generate ids which will not collide
+   * in the consumer page.  Implementation merely calls the static form of this
+   * method.
    */
-  public static String getContainerClientId(FacesContext context, String additionalId)
+
+  @Override
+  public String getContainerClientId(FacesContext context)
   {
-    ExternalContext ec = context.getExternalContext();
-    String namespace = ec.encodeNamespace(SEPARATOR);
+    // only add NamingContainer behavior when running in a portlet request
+    if (BridgeUtil.isPortletRequest())
+    {
 
-    /*
-     * In servlet world encodeNamespace does nothing -- so if we get back what we sent in then do
-     * not perturn the NamingContainer Id
+    /* Note: In portlet 1.0 the namespace is guaranteed valid for the request it
+     * was passed -- so its possible that resusing the saved one will no longer
+     * be valid.  However this is less likely than JSF expecting to not use the
+     * clientId from here to refer to an element in the reconstructed tree -- 
+     * Note though this is also unlikely we know of portlet 1.0 extended impls
+     * that support ajax via an extended portlet 1.0 where they run the full 
+     * lifecycle during a render and hence need action semantics in the render
      */
-    if (namespace.length() > 1)
-    {
-      if (additionalId != null)
+      if (mNamespace != null || (mNamespace = (String) this.getAttributes().get(PORTLET_NAMESPACE_ID)) != null)
       {
-        return namespace + additionalId;
+        return mNamespace;
       }
-      else
+      /* Can only calculate the namespace during a render (in portlet 1.0) */
+      else if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE)
       {
-        return namespace;
+        ExternalContext ec = context.getExternalContext();
+        mNamespace = ec.encodeNamespace("");
+        // also write it as a component so it is preserved across save/restore
+        // using the same value ensures consistentcy in portlet environments where
+        // such a namespace varies by request
+        this.getAttributes().put(PORTLET_NAMESPACE_ID, mNamespace);
+        return mNamespace;
       }
+      else
+        throw new NullPointerException("getContainerClientId: null portlet namespace in non-render phase");
     }
-    else
-    {
-      return null;
-    }
-  }
 
-  /**
-   * Implements NamingContainer semantics.  Ensures that the returned identifier
-   * contains the consumer (portal) provided unique portlet id.  This ensures that
-   * those components in this NamingContainer generate ids which will not collide
-   * in the consumer page.  Implementation merely calls the static form of this
-   * method.
-   */
+    return null;
 
-  @Override
-  public String getContainerClientId(FacesContext context)
-  {
-    return PortletNamingContainerUIViewRoot
-                                           .getContainerClientId(
-                                                                 context,
-                                                                 super
-                                                                      .getContainerClientId(context));
   }
-
+  
 }

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/resources/META-INF/NOTICE?rev=734815&r1=734814&r2=734815&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/resources/META-INF/NOTICE (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/api/src/main/resources/META-INF/NOTICE Thu Jan 15 12:49:33 2009
@@ -1,7 +1,7 @@
 Apache MyFaces Portlet Bridge
-Copyright [2007, 2008] The Apache Software Foundation
+Copyright [2007, 2008, 2009] The Apache Software Foundation
 
-This is an implementation of a public review specification
+This is an implementation of an early draft specification
 developed under the Java Community Process (JCP). This
 implementation may not fully conform to this specification.
 This implementation may differ from the final specification.

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletViewHandlerImpl.java?rev=734815&r1=734814&r2=734815&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletViewHandlerImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletViewHandlerImpl.java Thu Jan 15 12:49:33 2009
@@ -34,11 +34,13 @@
 import java.util.Map;
 import java.util.logging.Level;
 
+import javax.faces.application.Application;
 import javax.faces.FacesException;
 import javax.faces.FactoryFinder;
 import javax.faces.application.StateManager;
 import javax.faces.application.ViewHandler;
 import javax.faces.application.ViewHandlerWrapper;
+import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
@@ -98,13 +100,24 @@
     // We recognize this EL expresion here and evaluate to a viewid
     // before delegating// Do nothing when not running in portlet request
     
-    if (BridgeUtil.isPortletRequest() && viewId.startsWith("#"))
+    if (BridgeUtil.isPortletRequest())
     {
-      // evaluate this as an EL expression
-      viewId = (String) context.getApplication().evaluateExpressionGet(context, viewId, String.class);
-      if (viewId == null)
+      /* Note: later versions of glassfish jsf append a / if not in the nav rule
+      * -- remove it if blocking the expression.
+      */
+      if (viewId.startsWith("/#"))
+      {
+        viewId = viewId.substring(1);
+      }
+      
+      if (viewId.startsWith("#"))
       {
-        //TODO:  at least log an error.
+        // evaluate this as an EL expression
+        viewId = (String) context.getApplication().evaluateExpressionGet(context, viewId, String.class);
+        if (viewId == null)
+        {
+          //TODO:  at least log an error.
+        }
       }
     }
     
@@ -129,13 +142,24 @@
     // before delegating
     // Do nothing when not running in portlet request
     
-    if (BridgeUtil.isPortletRequest() && viewId.startsWith("#"))
+    if (BridgeUtil.isPortletRequest())
     {
-      // evaluate this as an EL expression
-      viewId = (String) facesContext.getApplication().evaluateExpressionGet(facesContext, viewId, String.class);
-      if (viewId == null)
+      /* Note: later versions of glassfish jsf append a / if not in the nav rule
+      * -- remove it if blocking the expression.
+      */
+      if (viewId.startsWith("/#"))
+      {
+        viewId = viewId.substring(1);
+      }
+      
+      if (viewId.startsWith("#"))
       {
-        //TODO:  at least log an error.
+        // evaluate this as an EL expression
+        viewId = (String) facesContext.getApplication().evaluateExpressionGet(facesContext, viewId, String.class);
+        if (viewId == null)
+        {
+          //TODO:  at least log an error.
+        }
       }
     }
     
@@ -150,27 +174,48 @@
     if (qsLoc < 0)
       qsLoc = viewId.length();
 
-    viewRoot = super.createView(facesContext, viewId.substring(0, qsLoc));
-    if (qsLoc < viewId.length())
+    String prior = setUIViewRootComponent(facesContext);
+    try 
     {
-      viewRoot.setViewId(viewRoot.getViewId().concat(viewId.substring(qsLoc)));
+      viewRoot = super.createView(facesContext, viewId.substring(0, qsLoc));
     }
-    
-    if (BridgeUtil.isPortletRequest())
+    finally
     {
-      // Use the delegatees UIViewRoot if its not the native Faces one
-      // or it already implements the PortletNamingContainer behavior
-      if ((viewRoot.getClass() == UIViewRoot.class) && 
-        (viewRoot.getClass().getAnnotation(PortletNamingContainer.class) == null))
-      {
-        return new PortletNamingContainerUIViewRoot(viewRoot);
-      }     
+      if (prior != null)
+        resetUIViewRootComponent(facesContext, prior);
     }
     
+    if (qsLoc < viewId.length())
+    {
+      viewRoot.setViewId(viewRoot.getViewId().concat(viewId.substring(qsLoc)));
+    }
+       
     return viewRoot;
 
   }
   
+  private String setUIViewRootComponent(FacesContext context)
+  {
+    Application app = context.getApplication();
+    UIComponent root = app.createComponent(UIViewRoot.COMPONENT_TYPE);
+    if (root == null || (root.getClass() == UIViewRoot.class && 
+        root.getClass().getAnnotation(PortletNamingContainer.class) == null))
+    {
+      app.addComponent(UIViewRoot.COMPONENT_TYPE, PortletNamingContainerUIViewRoot.class.getName());
+      return UIViewRoot.class.getName();
+    }
+    
+    return null;
+  }
+  
+  private void resetUIViewRootComponent(FacesContext context, String componentClassName)
+  {
+    if (componentClassName != null)
+    {
+      context.getApplication().addComponent(UIViewRoot.COMPONENT_TYPE, componentClassName);
+    }
+  }
+  
   
   @Override
   public UIViewRoot restoreView(FacesContext context, String viewId)

Modified: myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/resources/META-INF/NOTICE?rev=734815&r1=734814&r2=734815&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/resources/META-INF/NOTICE (original)
+++ myfaces/portlet-bridge/core/trunk_2.0.x/impl/src/main/resources/META-INF/NOTICE Thu Jan 15 12:49:33 2009
@@ -1,7 +1,7 @@
 Apache MyFaces Portlet Bridge
-Copyright [2007, 2008] The Apache Software Foundation
+Copyright [2007, 2008, 2009] The Apache Software Foundation
 
-This is an implementation of a public review specification
+This is an implementation of an early draft specification
 developed under the Java Community Process (JCP). This
 implementation may not fully conform to this specification.
 This implementation may differ from the final specification.