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 2011/03/30 03:01:46 UTC

svn commit: r1086816 - in /myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main: java/org/apache/myfaces/portlet/faces/application/ java/org/apache/myfaces/portlet/faces/application/view/ java/org/apache/myfaces/portlet/faces/bridge/ java/org/apache/m...

Author: mfreedman
Date: Wed Mar 30 01:01:45 2011
New Revision: 1086816

URL: http://svn.apache.org/viewvc?rev=1086816&view=rev
Log:
PORTLETBRIDGE-204: Bridge doesn't work with Mojarra 2.0.4.b09

Added:
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletRenderKitWrapperImpl.java
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletResponseStateManagerImpl.java
Removed:
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/services/javax.faces.application.ApplicationFactory
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/services/javax.faces.context.ExternalContextFactory
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/services/javax.faces.context.FacesContextFactory
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/services/javax.faces.view.ViewDeclarationLanguageFactory
Modified:
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletStateManagerImpl.java
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/view/AggregatingViewDeclatationLanguage.java
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletPartialViewContextImpl.java
    myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/faces-config.xml

Added: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletRenderKitWrapperImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletRenderKitWrapperImpl.java?rev=1086816&view=auto
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletRenderKitWrapperImpl.java (added)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletRenderKitWrapperImpl.java Wed Mar 30 01:01:45 2011
@@ -0,0 +1,85 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.faces.application;
+
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.StringWriter;
+
+import java.util.Map;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.faces.FacesException;
+import javax.faces.application.StateManager;
+import javax.faces.application.StateManagerWrapper;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitWrapper;
+import javax.faces.render.ResponseStateManager;
+
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeUtil;
+
+import org.apache.myfaces.portlet.faces.bridge.BridgeImpl;
+
+public class PortletRenderKitWrapperImpl
+  extends RenderKitWrapper
+{
+  private RenderKit mDelegatee = null;
+  private ResponseStateManager mRsm = null;
+
+  public PortletRenderKitWrapperImpl(RenderKit rk)
+  {
+    mDelegatee = rk;
+
+  }
+
+  public ResponseStateManager getResponseStateManager()
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    
+    if (BridgeUtil.getPortletRequestPhase() != Bridge.PortletPhase.RENDER_PHASE || 
+        ctx.getExternalContext().getRequestMap().get(BridgeImpl.SAVED_VIEW_STATE) == null)
+    {
+      return super.getResponseStateManager();
+    }
+    
+    if (mRsm == null)
+    {
+      mRsm = new PortletResponseStateManagerImpl(super.getResponseStateManager());
+    }
+    
+    return mRsm;
+  }
+  
+  public RenderKit getWrapped()
+  {
+    return mDelegatee;
+  }
+  
+}

Added: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletResponseStateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletResponseStateManagerImpl.java?rev=1086816&view=auto
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletResponseStateManagerImpl.java (added)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletResponseStateManagerImpl.java Wed Mar 30 01:01:45 2011
@@ -0,0 +1,109 @@
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.faces.application;
+
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.StringWriter;
+
+import java.util.Map;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.faces.FacesException;
+import javax.faces.application.StateManager;
+import javax.faces.application.StateManagerWrapper;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import javax.faces.render.ResponseStateManager;
+
+import javax.portlet.faces.Bridge;
+import javax.portlet.faces.BridgeUtil;
+
+import org.apache.myfaces.portlet.faces.bridge.BridgeImpl;
+
+public class PortletResponseStateManagerImpl
+  extends ResponseStateManager
+{
+  private ResponseStateManager mDelegatee = null;
+
+  public PortletResponseStateManagerImpl(ResponseStateManager rsm)
+  {
+    mDelegatee = rsm;
+
+  }
+  
+  public Object getComponentStateToRestore(FacesContext context)
+  {
+    return mDelegatee.getComponentStateToRestore(context);
+  }
+  
+  public Object getState(FacesContext context, String viewId)
+  {
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    
+    if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE && 
+        ctx.getExternalContext().getRequestMap().get(BridgeImpl.SAVED_VIEW_STATE) != null)
+    {
+      // don't remove in case we are called again in this request. -- it will get removed from the
+      // bridge request scope later (after the save) to avoid its reuse
+      return ctx.getExternalContext().getRequestMap().get(BridgeImpl.SAVED_VIEW_STATE);
+    }
+    else
+    {
+      return mDelegatee.getState(context, viewId); 
+    }
+  }
+
+  public Object getTreeStructureToRestore(FacesContext context,
+                                          String viewId)
+  {
+    return mDelegatee.getTreeStructureToRestore(context, viewId);
+  }
+  
+  public String getViewState(FacesContext context,
+                             Object state)
+  {
+    return mDelegatee.getViewState(context, state); 
+  }
+  
+  public boolean isPostback(FacesContext context)
+  {
+    return mDelegatee.isPostback(context);
+  }
+  
+  public void writeState(FacesContext context, Object state) throws IOException
+  {
+    mDelegatee.writeState(context, state);
+    return;
+  }
+  
+  public void writeState(FacesContext context, StateManager.SerializedView state) throws IOException
+  {
+    mDelegatee.writeState(context, state);
+    return;
+  }
+}

Modified: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletStateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletStateManagerImpl.java?rev=1086816&r1=1086815&r2=1086816&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletStateManagerImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/PortletStateManagerImpl.java Wed Mar 30 01:01:45 2011
@@ -19,18 +19,27 @@
 
 package org.apache.myfaces.portlet.faces.application;
 
+
 import java.io.IOException;
 import java.io.StringWriter;
 
+import java.util.HashMap;
 import java.util.Map;
 
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.faces.FactoryFinder;
 import javax.faces.application.StateManager;
 import javax.faces.application.StateManagerWrapper;
+import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
 import javax.faces.render.ResponseStateManager;
 
+import javax.portlet.faces.Bridge;
 import javax.portlet.faces.BridgeUtil;
 
 import org.apache.myfaces.portlet.faces.bridge.BridgeImpl;
@@ -39,35 +48,80 @@ public class PortletStateManagerImpl
   extends StateManagerWrapper
 {
   private StateManager mDelegatee = null;
-  
+  private HashMap<String, RenderKit> mWrappedRenderKits = null;
+  private RenderKitFactory mRenderKitFactory = null;
+
   public PortletStateManagerImpl(StateManager sm)
   {
     mDelegatee = sm;
+    mWrappedRenderKits = new HashMap<String, RenderKit>(5);
   }
   
+  public UIViewRoot restoreView(FacesContext context,
+                                       String viewId,
+                                       String renderKitId) throws IllegalArgumentException
+  {
+    UIViewRoot result = null;
+    
+    if (renderKitId == null) throw new IllegalArgumentException("null renderKitId in restoreView.");
+
+    
+    // Only wrap the RenderKit and use if needed for this restore:
+    if (BridgeUtil.getPortletRequestPhase() == Bridge.PortletPhase.RENDER_PHASE && 
+        context.getExternalContext().getRequestMap().get(BridgeImpl.SAVED_VIEW_STATE) != null)
+    {
+      RenderKit curRK = getRenderKitFactory().getRenderKit(context, renderKitId);
+      RenderKit rk = mWrappedRenderKits.get(renderKitId);
+      if (!curRK.equals(rk))
+      {
+        if (rk == null)
+        {
+          rk = new PortletRenderKitWrapperImpl(curRK);
+          mWrappedRenderKits.put(renderKitId, rk);
+        }
+        getRenderKitFactory().addRenderKit(renderKitId, rk);
+      }
+      
+      result = super.restoreView(context, viewId, renderKitId);
+      
+      // now restore the unwrapped renderKit
+      getRenderKitFactory().addRenderKit(renderKitId, curRK);
+    }
+    else
+    {
+      result = super.restoreView(context, viewId, renderKitId);
+    }
+    
+    return result;
+    
+  }
+
+
+
   /*
    * Override saveView so we can grab the returned state and place
    * it in the request scope so the Bridge can find it and use for subsequent
    * renders that occur in this managed bridge (action) request scope.
-   * 
+   *
    * Basically what is going one here is that JSF either stores the entire state
    * or at least enough info to get back to its entire state in a hidden field
    * represented by the VIEW_STATE_PARAM.  In addition the existence of this
    * parameter in any given request is used to determine if one is running in a
-   * postback or not.  
+   * postback or not.
    * Because in the portlet environment renders occur in a separate request from
-   * action we need to preserve this parameter in the first request after an 
+   * action we need to preserve this parameter in the first request after an
    * action so JSF will know its in a postback.  However after the first render
    * following an action additional renders can occur (before the next action).
    * These renders also need to signal they are running in a postback by exposing
-   * this parameter however the value should not be the one that was sent to the 
+   * this parameter however the value should not be the one that was sent to the
    * original action but rather the one that resulted after the last render.
-   * 
+   *
    * To do this the Bridge has to catch the value that is being written into
-   * the hidden field.  It does this by overriding writeState and replace the 
+   * the hidden field.  It does this by overriding writeState and replace the
    * value its maintaining for the VIEW_STATE_PARAM with this value written as
    * a String.
    */
+
   public void writeState(FacesContext context, Object state)
     throws IOException
   {
@@ -83,31 +137,31 @@ public class PortletStateManagerImpl
     StringWriter stringWriter = new StringWriter(128);
     ResponseWriter newRW = oldRW.cloneWithWriter(stringWriter);
     context.setResponseWriter(newRW);
-    
+
     super.writeState(context, state);
-    
+
     // Restore real responsewriter
     context.setResponseWriter(oldRW);
-    
+
     // Get written state
     newRW.flush();
     String stateValue = new String(stringWriter.getBuffer());
-    
+
 
     // Write it to the old response writer
     oldRW.write(stateValue);
-    
+
     // Now extract the parameter value from the buffer:
     stateValue = extractViewStateParamValue(stateValue);
-    
-    if (stateValue != null) 
+
+    if (stateValue != null)
     {
       Map<String, Object> m = context.getExternalContext().getRequestMap();
       m.put(BridgeImpl.UPDATED_VIEW_STATE_PARAM, stateValue);
     }
-    
+
   }
-  
+
   public void writeState(FacesContext context, SerializedView state)
     throws IOException
   {
@@ -123,42 +177,44 @@ public class PortletStateManagerImpl
     StringWriter stringWriter = new StringWriter(128);
     ResponseWriter newRW = oldRW.cloneWithWriter(stringWriter);
     context.setResponseWriter(newRW);
-    
+
     super.writeState(context, state);
-    
+
     // Restore real responsewriter
     context.setResponseWriter(oldRW);
-    
+
     // Get written state
     newRW.flush();
     String stateValue = new String(stringWriter.getBuffer());
-    
+
 
     // Write it to the old response writer
     oldRW.write(stateValue);
-    
+
     // Now extract the parameter value from the buffer:
     stateValue = extractViewStateParamValue(stateValue);
-    
-    if (stateValue != null) 
+
+    if (stateValue != null)
     {
       Map<String, Object> m = context.getExternalContext().getRequestMap();
       m.put(BridgeImpl.UPDATED_VIEW_STATE_PARAM, stateValue);
     }
-    
+
   }
-  
+
+
   public StateManager getWrapped()
   {
     return mDelegatee;
   }
-  
+
   private String extractViewStateParamValue(String buf)
   {
     // Locate the VIEW_STATE_PARAM field
     int i = buf.indexOf(ResponseStateManager.VIEW_STATE_PARAM);
-    if (i < 0) return null;
-    
+    if (i < 0)
+      return null;
+
     // now locate the end of the element so don't read beyond it.
     // TODO: improve finding end of element/attribute as these values
     // could exist in the VIEW_STATE_PARAM output
@@ -168,25 +224,41 @@ public class PortletStateManagerImpl
       end = buf.indexOf(">", i);
     if (end < 0)
       return null;
-    
+
     // now locate the value attribute
     int valStart = buf.indexOf("value", i);
-    if (valStart < 0 || valStart > end) 
+    if (valStart < 0 || valStart > end)
     {
       // must be earlier in the element
       buf = buf.substring(0, end);
       end = buf.length() - 1;
       i = buf.lastIndexOf("<");
-      if (i < 0) return null;
+      if (i < 0)
+        return null;
       valStart = buf.indexOf("value", i);
-      if (valStart < 0) return null;
+      if (valStart < 0)
+        return null;
     }
-    
+
     // now extract the value between the quotes
     valStart = buf.indexOf('"', valStart);
-    if (valStart < 0) return null;
+    if (valStart < 0)
+      return null;
     int valEnd = buf.indexOf('"', valStart + 1);
-    if (valEnd < 0 || valEnd > end) return null;
+    if (valEnd < 0 || valEnd > end)
+      return null;
     return buf.substring(valStart + 1, valEnd);
   }
+  
+
+  protected RenderKitFactory getRenderKitFactory()
+  {
+      if (mRenderKitFactory == null)
+      {
+          mRenderKitFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+      }
+      return mRenderKitFactory;
+  }
+
+
 }

Modified: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/view/AggregatingViewDeclatationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/view/AggregatingViewDeclatationLanguage.java?rev=1086816&r1=1086815&r2=1086816&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/view/AggregatingViewDeclatationLanguage.java (original)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/application/view/AggregatingViewDeclatationLanguage.java Wed Mar 30 01:01:45 2011
@@ -15,6 +15,7 @@ import java.beans.BeanInfo;
 import java.io.IOException;
 
 import javax.faces.application.Resource;
+import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.view.StateManagementStrategy;
@@ -120,7 +121,18 @@ class AggregatingViewDeclatationLanguage
   @Override
   public UIViewRoot restoreView(FacesContext arg0, String arg1)
   {
-    return mPrimary.restoreView(arg0, arg1);
+    UIViewRoot vr = mPrimary.restoreView(arg0, arg1);
+    
+    
+    // Workaround Trinidad bug where it doesn't set the renderkit Id in the VR
+    // after/during restore -- which causes a NPE in Mojarra 1.2.0.4
+    if (vr != null && vr.getRenderKitId() == null)
+    {
+      ViewHandler outerViewHandler =
+            arg0.getApplication().getViewHandler();
+      vr.setRenderKitId(outerViewHandler.calculateRenderKitId(arg0));
+    }
+    return vr;
   }
 
 }

Modified: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java?rev=1086816&r1=1086815&r2=1086816&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/BridgeImpl.java Wed Mar 30 01:01:45 2011
@@ -51,15 +51,20 @@ import javax.faces.FactoryFinder;
 import javax.faces.application.Application;
 import javax.faces.application.ApplicationFactory;
 import javax.faces.application.FacesMessage;
+import javax.faces.application.StateManager;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExceptionHandler;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.FacesContextFactory;
+import javax.faces.event.AbortProcessingException;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
+import javax.faces.event.PostConstructApplicationEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
 import javax.faces.lifecycle.Lifecycle;
 import javax.faces.lifecycle.LifecycleFactory;
 import javax.faces.render.ResponseStateManager;
@@ -117,6 +122,7 @@ import javax.servlet.http.HttpSessionBin
 
 import javax.servlet.http.HttpSessionEvent;
 
+import org.apache.myfaces.portlet.faces.application.PortletStateManagerImpl;
 import org.apache.myfaces.portlet.faces.bridge.wrapper.BridgePortletRequestWrapper;
 import org.apache.myfaces.portlet.faces.bridge.wrapper.BridgeRenderRequestWrapper;
 import org.apache.myfaces.portlet.faces.context.PortletExceptionHanderFactoryImpl;
@@ -128,7 +134,7 @@ import org.apache.myfaces.portlet.faces.
 import org.apache.myfaces.portlet.faces.util.config.WebConfigurationProcessor;
 
 public class BridgeImpl
-  implements Bridge, ELContextListener, PhaseListener, ServletRequestAttributeListener
+  implements Bridge, ELContextListener, PhaseListener, ServletRequestAttributeListener, SystemEventListener
 {
   private static final long serialVersionUID = 5807626987246270989L;
 
@@ -159,6 +165,8 @@ public class BridgeImpl
   private static final String NULL_VIEW_STATE_PARAM_VALUE = "org.apache.myfaces.portlet.faces.nullViewState";
   private static final String CACHED_VIEWROOT_LOCALE = "org.apache.myfaces.portlet.faces.cachedViewRootLocale";
   private static final String PROCESSED_PUBLIC_PARAMS ="org.apache.myfaces.portlet.faces.processedPublicParams";
+  public static final String SAVED_VIEW_STATE = "org.apache.myfaces.portlet.faces.includeInScope.saveViewState";
+
   private static final int DEFAULT_MAX_MANAGED_REQUEST_SCOPES = 100;
 
   private Boolean mPreserveActionParams = Boolean.FALSE;
@@ -287,7 +295,28 @@ public class BridgeImpl
     mInitialized = true;
 
   }
-
+  
+  @Override
+  public void processEvent(SystemEvent event) throws AbortProcessingException
+  {
+    if(event instanceof PostConstructApplicationEvent)
+    {
+      // Install the Bridge StateManager -- wrapping the others -- we need to 
+      // be first (ratehr than last) so the action/render view save/restore will work
+      Application app = ((PostConstructApplicationEvent) event).getApplication();
+      app.setStateManager(new PortletStateManagerImpl(app.getStateManager()));
+    }
+  }
+  
+  
+  @Override
+  public boolean isListenerForSource(Object source)
+  {
+    //only for Application
+    return (source instanceof Application);
+  
+  }
+  
   public void doFacesRequest(ActionRequest request, ActionResponse response)
     throws BridgeException,
            BridgeDefaultViewNotSpecifiedException,
@@ -1649,19 +1678,23 @@ public class BridgeImpl
     saveFacesMessageState(context);
 
     // now place the viewRoot in the request scope
+    /*
     UIViewRoot vr = context.getViewRoot();
     Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
     requestMap.put(FACES_VIEWROOT, vr);
     
     // Preserve the FC scope so its not lost when restart this lifecycle in the render
-    HashMap<Object, Object> preserved = mPreservedFacesContextScopeAttrs(context);
+    HashMap<Object, Object> preserved = preserveFacesContextScopeAttrs(context);
     if (preserved != null)
     {
       requestMap.put(FACES_CONTEXT_SCOPE, preserved);
     }
+    */
+    context.getExternalContext().getRequestMap().put(SAVED_VIEW_STATE, context.getApplication().getStateManager().saveView(context));
+    
   }
   
-  private HashMap<Object, Object> mPreservedFacesContextScopeAttrs(FacesContext context)
+  private HashMap<Object, Object> preserveFacesContextScopeAttrs(FacesContext context)
   {
      if (mPreservedFacesContextScopeAttrs == null || mPreservedFacesContextScopeAttrs.isEmpty())
      {
@@ -1695,6 +1728,7 @@ public class BridgeImpl
   
   private boolean restoreFacesView(FacesContext context, String scopeId)
   {
+    /*
     Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
     UIViewRoot viewRoot = (UIViewRoot) requestMap.remove(FACES_VIEWROOT);
     if (viewRoot != null)
@@ -1724,6 +1758,8 @@ public class BridgeImpl
     // Messages get restored in a phase listener
     
     return viewRoot != null;
+    */
+    return false;
   }  
 
   private void saveActionParams(FacesContext context)
@@ -1825,6 +1861,7 @@ public class BridgeImpl
       // be in the scope (as well as its FC scope.  Remove it so its not used again.
       // get the managedScopeMap
       scopeMap.remove(FACES_VIEWROOT);
+      scopeMap.remove(SAVED_VIEW_STATE);
       Map<Object, Object> attrs = (Map<Object, Object>) scopeMap.remove(FACES_CONTEXT_SCOPE);
       if (attrs != null)
       {

Modified: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletPartialViewContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletPartialViewContextImpl.java?rev=1086816&r1=1086815&r2=1086816&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletPartialViewContextImpl.java (original)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletPartialViewContextImpl.java Wed Mar 30 01:01:45 2011
@@ -150,7 +150,7 @@ public class PortletPartialViewContextIm
   
   private String fixUpClientId(String id, String bridgeVRPrefix)
   {
-    if (!id.startsWith(bridgeVRPrefix))
+    if (!id.startsWith("@") && !id.startsWith(bridgeVRPrefix))
     {
       id = new StringBuffer(bridgeVRPrefix).append(":").append(id).toString();
     }

Modified: myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/faces-config.xml?rev=1086816&r1=1086815&r2=1086816&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/faces-config.xml (original)
+++ myfaces/portlet-bridge/core/trunk_3.0.x/impl/src/main/resources/META-INF/faces-config.xml Wed Mar 30 01:01:45 2011
@@ -22,10 +22,26 @@
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
 
+    <name>MyFacesPortletBridge</name>
+    <ordering>
+	    <before><others/></before>
+    </ordering>
+
     <application>
+        <!-- StateManager is installed manually by bridge in the PostConstructApplicationEvent so we can wrap
+             all other and be first to be called - needed to handle save/restore across action  -->
         <view-handler>org.apache.myfaces.portlet.faces.application.PortletViewHandlerImpl</view-handler>
-        <state-manager>org.apache.myfaces.portlet.faces.application.PortletStateManagerImpl</state-manager>
         <el-resolver>org.apache.myfaces.portlet.faces.el.PortletELResolver</el-resolver>
+
+    	  <!-- Application is started -->
+    	  <system-event-listener>
+		<system-event-listener-class>
+			org.apache.myfaces.portlet.faces.bridge.BridgeImpl
+		</system-event-listener-class>
+		<system-event-class>
+			javax.faces.event.PostConstructApplicationEvent
+		</system-event-class>    					
+    	  </system-event-listener>
         <application-extension>
           <bridge:excluded-attributes>
             <bridge:excluded-attribute>com.sun.faces.*</bridge:excluded-attribute>
@@ -39,6 +55,10 @@
         </application-extension>
     </application>
     <factory>
+	<application-factory>org.apache.myfaces.portlet.faces.application.PortletApplicationFactoryImpl</application-factory>
+	<faces-context-factory>org.apache.myfaces.portlet.faces.context.PortletFacesContextFactoryImpl</faces-context-factory>
+	<external-context-factory>org.apache.myfaces.portlet.faces.context.PortletExternalContextFactoryImpl</external-context-factory>
+      <view-declaration-language-factory>org.apache.myfaces.portlet.faces.application.view.PortletViewDeclarationLanguageFactoryImpl</view-declaration-language-factory>
       <exception-handler-factory>org.apache.myfaces.portlet.faces.context.PortletExceptionHanderFactoryImpl</exception-handler-factory>
       <partial-view-context-factory>org.apache.myfaces.portlet.faces.context.PortletPartialViewContextFactoryImpl</partial-view-context-factory>
     </factory>