myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1100247 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: application/ view/facelets/compiler/ view/facelets/tag/jsf/
Date Fri, 06 May 2011 15:03:50 GMT
Author: lu4242
Date: Fri May  6 15:03:50 2011
New Revision: 1100247

URL: http://svn.apache.org/viewvc?rev=1100247&view=rev
Log:
MYFACES-2924 Component bindings are not reset when explicit navigation to the same page is
derived from action

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ClearBindingValueExpressionListener.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/PreDisposeViewEvent.java
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java?rev=1100247&r1=1100246&r2=1100247&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
Fri May  6 15:03:50 2011
@@ -37,8 +37,12 @@ import javax.faces.application.FacesMess
 import javax.faces.application.NavigationCase;
 import javax.faces.application.ProjectStage;
 import javax.faces.application.ViewHandler;
+import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewParameter;
 import javax.faces.component.UIViewRoot;
+import javax.faces.component.visit.VisitCallback;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.PartialViewContext;
@@ -49,6 +53,7 @@ import org.apache.myfaces.config.Runtime
 import org.apache.myfaces.config.element.NavigationRule;
 import org.apache.myfaces.shared_impl.util.HashMapUtils;
 import org.apache.myfaces.shared_impl.util.StringUtils;
+import org.apache.myfaces.view.facelets.tag.jsf.PreDisposeViewEvent;
 
 /**
  * @author Thomas Spiegl (latest modification by $Author$)
@@ -61,6 +66,8 @@ public class NavigationHandlerImpl
     //private static final Log log = LogFactory.getLog(NavigationHandlerImpl.class);
     private static final Logger log = Logger.getLogger(NavigationHandlerImpl.class.getName());
 
+    private static final String SKIP_ITERATION_HINT = "javax.faces.visit.SKIP_ITERATION";
+    
     private static final String ASTERISK = "*";
 
     private Map<String, Set<NavigationCase>> _navigationCases = null;
@@ -152,6 +159,13 @@ public class NavigationHandlerImpl
                     partialViewContext.setRenderAll(true);
                 }
 
+                if (facesContext.getViewRoot().getAttributes().containsKey("oam.CALL_PRE_DISPOSE_VIEW"))
+                {
+                    facesContext.getAttributes().put(SKIP_ITERATION_HINT, Boolean.TRUE);
+                    facesContext.getViewRoot().visitTree(VisitContext.createVisitContext(facesContext),
new PreDisposeViewCallback());
+                    facesContext.getAttributes().remove(SKIP_ITERATION_HINT);
+                }
+
                 // create UIViewRoot for new view
                 UIViewRoot viewRoot = null;
                 
@@ -196,6 +210,16 @@ public class NavigationHandlerImpl
         }
     }
 
+    private static class PreDisposeViewCallback implements VisitCallback
+    {
+
+        public VisitResult visit(VisitContext context, UIComponent target)
+        {
+            context.getFacesContext().getApplication().publishEvent(context.getFacesContext(),
PreDisposeViewEvent.class, target);
+            
+            return VisitResult.ACCEPT;
+        }
+    }
 
     /**
      * Returns the navigation case that applies for the given action and outcome
@@ -684,4 +708,4 @@ public class NavigationHandlerImpl
         return apiCases;
     }
 
-}
\ No newline at end of file
+}

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java?rev=1100247&r1=1100246&r2=1100247&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/UIInstructionHandler.java
Fri May  6 15:03:50 2011
@@ -92,9 +92,9 @@ final class UIInstructionHandler extends
             UIComponent c = null;
             FaceletCompositionContext mctx= FaceletCompositionContext.getCurrentInstance(ctx);
             boolean componentFoundInserted = false;
-            // MYFACES-2924 This optimization does not work as expected when component bindings
are used.
-            //if (mctx.isRefreshingTransientBuild())
-            //{
+            
+            if (mctx.isRefreshingTransientBuild())
+            {
                 c = ComponentSupport.findChildByTagId(parent, id);
                 /*
                 if (c == null && mctx.isRefreshTransientBuildOnPSS() && 
@@ -137,7 +137,7 @@ final class UIInstructionHandler extends
                     }
                 }
                 */
-            //}
+            }
             boolean componentFound = false;
             if (c != null)
             {

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ClearBindingValueExpressionListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ClearBindingValueExpressionListener.java?rev=1100247&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ClearBindingValueExpressionListener.java
(added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ClearBindingValueExpressionListener.java
Fri May  6 15:03:50 2011
@@ -0,0 +1,76 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import java.io.Serializable;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.el.ELException;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.ComponentSystemEventListener;
+
+/**
+ * MyFaces specific listener used to clear all component binding if
+ * normal navigation occur during a POST request.
+ * 
+ * @author Leonardo Uribe
+ * @since 2.0.6
+ *
+ */
+public class ClearBindingValueExpressionListener implements ComponentSystemEventListener,
Serializable
+{
+    
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -6066524284031941519L;
+    
+    public ClearBindingValueExpressionListener()
+    {
+        super();
+    }
+
+    public void processEvent(ComponentSystemEvent event)
+    {
+        try
+        {
+            event.getComponent().getValueExpression("binding").setValue(
+                    FacesContext.getCurrentInstance().getELContext(), null);
+        }
+        catch(ELException e)
+        {
+            Logger log = Logger.getLogger(ClearBindingValueExpressionListener.class.getName());
+            if (log.isLoggable(Level.FINE))
+            {
+                log.log(Level.FINE, "Cannot reset binding for: " + event.getComponent().getClientId(),
e);
+            }
+        }
+        catch(NullPointerException e)
+        {
+            Logger log = Logger.getLogger(ClearBindingValueExpressionListener.class.getName());
+            if (log.isLoggable(Level.FINE))
+            {
+                log.log(Level.FINE, "Cannot reset binding for: " + event.getComponent().getClientId(),
e);
+            }
+        }
+    }
+
+}

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java?rev=1100247&r1=1100246&r2=1100247&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentTagHandlerDelegate.java
Fri May  6 15:03:50 2011
@@ -193,9 +193,9 @@ public class ComponentTagHandlerDelegate
         // grab our component
         UIComponent c = null;
         //boolean componentFoundInserted = false;
-        // MYFACES-2924 This optimization does not work as expected when component bindings
are used.
-        //if (mctx.isRefreshingTransientBuild())
-        //{
+        
+        if (mctx.isRefreshingTransientBuild())
+        {
             if (_relocatableResourceHandler != null)
             {
                 c = _relocatableResourceHandler.findChildByTagId(ctx, parent, id);
@@ -246,7 +246,7 @@ public class ComponentTagHandlerDelegate
                 }
             }
             */
-        //}
+        }
         boolean componentFound = false;
         if (c != null)
         {
@@ -513,6 +513,12 @@ public class ComponentTagHandlerDelegate
             if (c != null)
             {
                 c.setValueExpression("binding", ve);
+                
+                if (!ve.isReadOnly(faces.getELContext()))
+                {
+                    ComponentSupport.getViewRoot(ctx, c).getAttributes().put("oam.CALL_PRE_DISPOSE_VIEW",
Boolean.TRUE);
+                    c.subscribeToEvent(PreDisposeViewEvent.class, new ClearBindingValueExpressionListener());
+                }
             }
         }
         else

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/PreDisposeViewEvent.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/PreDisposeViewEvent.java?rev=1100247&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/PreDisposeViewEvent.java
(added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/PreDisposeViewEvent.java
Fri May  6 15:03:50 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.view.facelets.tag.jsf;
+
+import javax.faces.component.UIComponent;
+import javax.faces.event.ComponentSystemEvent;
+import javax.faces.event.FacesListener;
+import javax.faces.event.SystemEventListener;
+
+/**
+ * MyFaces specific event used to clear all component binding if
+ * normal navigation occur during a POST request.
+ * 
+ * NOTE: this event is not intended for use outside MyFaces Impl project.
+ * 
+ * @author Leonardo Uribe
+ * @since 2.0.6
+ *
+ */
+public class PreDisposeViewEvent extends ComponentSystemEvent
+{
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 8124621389770967678L;
+
+    public PreDisposeViewEvent(UIComponent component)
+    {
+        super(component);
+    }
+
+    @Override
+    public boolean isAppropriateListener(FacesListener listener)
+    {
+        return listener instanceof SystemEventListener;
+    }
+    
+    
+}



Mime
View raw message