myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1520154 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/view/facelets/el/ main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ test/java/org/apache/myfaces/view/facelets/tag/jsf/core/reset/ test/resources/org/apache/myf...
Date Wed, 04 Sep 2013 22:15:38 GMT
Author: lu4242
Date: Wed Sep  4 22:15:38 2013
New Revision: 1520154

URL: http://svn.apache.org/r1520154
Log:
MYFACES-3770 Implement <f:resetValues> tag and <f:ajax resetValues=true ... >


Added:
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_3.xhtml
      - copied, changed from r1520036, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_2.xhtml
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/
  (with props)
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/simpleButton.xhtml
  (with props)
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/CompositeComponentELUtils.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ResetValuesActionListenerHandler.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/reset/ResetValuesTestCase.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/CompositeComponentELUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/CompositeComponentELUtils.java?rev=1520154&r1=1520153&r2=1520154&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/CompositeComponentELUtils.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/CompositeComponentELUtils.java
Wed Sep  4 22:15:38 2013
@@ -252,6 +252,26 @@ public final class CompositeComponentELU
         return ccLevel.intValue();
     }
     
+    public static UIComponent getCompositeComponentBasedOnLocation(final FacesContext facesContext,

+            UIComponent baseComponent, final Location location)
+    {
+        UIComponent currentComponent = baseComponent;
+        while (currentComponent != null)
+        {
+            Location componentLocation = (Location) currentComponent.getAttributes().get(
+                LOCATION_KEY);
+            if (componentLocation != null 
+                    && componentLocation.getPath().equals(location.getPath()))
+            {
+                return currentComponent;
+            }
+            // get the composite component's parent
+            currentComponent = UIComponent.getCompositeComponentParent(currentComponent);
+        }
+        return null;
+    }
+
+    
     /**
      * Same as getCompositeComponentBasedOnLocation(final FacesContext facesContext, final
Location location),
      * but takes into account the ccLevel to resolve the composite component. 

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ResetValuesActionListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ResetValuesActionListenerHandler.java?rev=1520154&r1=1520153&r2=1520154&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ResetValuesActionListenerHandler.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/core/ResetValuesActionListenerHandler.java
Wed Sep  4 22:15:38 2013
@@ -36,6 +36,8 @@ import javax.faces.event.AbortProcessing
 import javax.faces.event.ActionEvent;
 import javax.faces.event.ActionListener;
 import javax.faces.view.ActionSource2AttachedObjectHandler;
+import javax.faces.view.AttachedObjectHandler;
+import javax.faces.view.Location;
 import javax.faces.view.facelets.ComponentHandler;
 import javax.faces.view.facelets.FaceletContext;
 import javax.faces.view.facelets.FaceletException;
@@ -47,6 +49,7 @@ import org.apache.myfaces.buildtools.mav
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 import org.apache.myfaces.view.facelets.FaceletCompositionContext;
+import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
 
 /**
  *
@@ -105,7 +108,7 @@ public class ResetValuesActionListenerHa
         }
         if (parent instanceof ActionSource)
         {
-            applyAttachedObject(ctx.getFacesContext(), parent);
+            applyAttachedObject(ctx.getFacesContext(), parent, false);
         }
         else if (UIComponent.isCompositeComponent(parent))
         {
@@ -126,21 +129,51 @@ public class ResetValuesActionListenerHa
 
     public void applyAttachedObject(FacesContext context, UIComponent parent)
     {
+        applyAttachedObject(context, parent, true);
+    }
+    
+    public void applyAttachedObject(FacesContext context, UIComponent parent, boolean checkForParentCC)
+    {
+        UIComponent topParentComponent = null;
         // Retrieve the current FaceletContext from FacesContext object
         FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(
                 FaceletContext.FACELET_CONTEXT_KEY);
+        
+        if (checkForParentCC)
+        {
+            FaceletCompositionContext mctx = FaceletCompositionContext.getCurrentInstance(faceletContext);
+            UIComponent parentComponent = parent;
+            while (parentComponent != null)
+            {
+                if (UIComponent.isCompositeComponent(parentComponent))
+                {
+                    List<AttachedObjectHandler> handlerList = mctx.getAttachedObjectHandlers(parentComponent);
+                    if (handlerList != null && handlerList.contains(this))
+                    {
+                        //Found, but we need to go right to the top for it. 
+                        topParentComponent = parentComponent;
+                    }
+                }
+                parentComponent = parentComponent.getParent();
+            }
+        }
 
         ActionSource as = (ActionSource) parent;
         ActionListener listener = null;
         if (_render.isLiteral())
         {
-            listener = new LiteralResetValuesActionListener(_clientIds);
-        
+            listener = new LiteralResetValuesActionListener(_clientIds,
+                topParentComponent != null ? 
+                (Location) topParentComponent.getAttributes().get(
+                    CompositeComponentELUtils.LOCATION_KEY) : null);
         }
         else
         {
             listener = new ResetValuesActionListener(_render
-                .getValueExpression(faceletContext, Object.class));
+                .getValueExpression(faceletContext, Object.class) ,
+                topParentComponent != null ? 
+                (Location) topParentComponent.getAttributes().get(
+                    CompositeComponentELUtils.LOCATION_KEY) : null);
         }
         as.addActionListener(listener);
     }
@@ -169,13 +202,16 @@ public class ResetValuesActionListenerHa
 
         private ValueExpression renderExpression;
         
+        private Location topCompositeComponentReference;
+        
         private ResetValuesActionListener()
         {
         }
         
-        public ResetValuesActionListener(ValueExpression renderExpression)
+        public ResetValuesActionListener(ValueExpression renderExpression, Location location)
         {
             this.renderExpression = renderExpression;
+            this.topCompositeComponentReference = location;
         }
 
         public void processAction(ActionEvent event) throws AbortProcessingException
@@ -212,7 +248,24 @@ public class ResetValuesActionListenerHa
             }
             
             // Calculate the final clientIds
-            UIComponent contextComponent = event.getComponent();
+            UIComponent contextComponent = null;
+            if (topCompositeComponentReference != null)
+            {
+                contextComponent = CompositeComponentELUtils.getCompositeComponentBasedOnLocation(
+                    faces, event.getComponent(), topCompositeComponentReference);
+                if (contextComponent == null)
+                {
+                    contextComponent = event.getComponent();
+                }
+                else
+                {
+                    contextComponent = contextComponent.getParent();
+                }
+            }
+            else
+            {
+                contextComponent = event.getComponent();
+            }
             List<String> list = new ArrayList<String>();
             for (String id : clientIds)
             {
@@ -230,13 +283,16 @@ public class ResetValuesActionListenerHa
 
         private Collection<String> clientIds;
         
+        private Location topCompositeComponentReference;
+        
         private LiteralResetValuesActionListener()
         {
         }
         
-        public LiteralResetValuesActionListener(Collection<String> clientIds)
+        public LiteralResetValuesActionListener(Collection<String> clientIds, Location
location)
         {
             this.clientIds = clientIds;
+            this.topCompositeComponentReference = location;
         }
 
         public void processAction(ActionEvent event) throws AbortProcessingException
@@ -253,7 +309,24 @@ public class ResetValuesActionListenerHa
             }
             
             // Calculate the final clientIds
-            UIComponent contextComponent = event.getComponent();
+            UIComponent contextComponent = null;
+            if (topCompositeComponentReference != null)
+            {
+                contextComponent = CompositeComponentELUtils.getCompositeComponentBasedOnLocation(
+                    faces, event.getComponent(), topCompositeComponentReference);
+                if (contextComponent == null)
+                {
+                    contextComponent = event.getComponent();
+                }
+                else
+                {
+                    contextComponent = contextComponent.getParent();
+                }
+            }
+            else
+            {
+                contextComponent = event.getComponent();
+            }
             List<String> list = new ArrayList<String>();
             for (String id : clientIds)
             {

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/reset/ResetValuesTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/reset/ResetValuesTestCase.java?rev=1520154&r1=1520153&r2=1520154&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/reset/ResetValuesTestCase.java
(original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/jsf/core/reset/ResetValuesTestCase.java
Wed Sep  4 22:15:38 2013
@@ -1,17 +1,20 @@
 /*
- * Copyright 2013 The Apache Software Foundation.
+ * 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
  *
- * 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
  *
- *      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.
+ * 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.core.reset;
 
@@ -85,6 +88,7 @@ public class ResetValuesTestCase extends
         processLifecycleExecute();
         processRender();
 
+        submitButton = facesContext.getViewRoot().findComponent("mainForm:submit");
         field1 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field1");
         field2 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field2");
         
@@ -110,6 +114,7 @@ public class ResetValuesTestCase extends
         processLifecycleExecute();
         processRender();
 
+        submitButton = facesContext.getViewRoot().findComponent("mainForm:submit");
         field1 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field1");
         field2 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field2");
         
@@ -141,6 +146,7 @@ public class ResetValuesTestCase extends
         processLifecycleExecute();
         processRender();
 
+        submitButton = facesContext.getViewRoot().findComponent("mainForm:submit");
         field1 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field1");
         field2 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field2");
         
@@ -153,4 +159,43 @@ public class ResetValuesTestCase extends
         Assert.assertEquals(Integer.valueOf(3), bean.getField2());
     }
 
+    @Test
+    public void testResetValuesActionListenerHandler3() throws Exception
+    {
+        setupRequest("/resetValuesActionListener_3.xhtml");
+
+        processLifecycleExecute();
+        
+        ResetValuesBean bean = facesContext.getApplication().evaluateExpressionGet(facesContext,

+            "#{bean}", ResetValuesBean.class);
+        
+        bean.setField1("Hello");
+        bean.setField2(1);
+        
+        executeBuildViewCycle(facesContext);
+                
+        UIComponent submitButton = facesContext.getViewRoot().findComponent("mainForm:submit:button");
+        
+        UIInput field1 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field1");
+        UIInput field2 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field2");
+        
+        executeViewHandlerRender(facesContext);
+        executeAfterRender(facesContext);
+        
+        client.inputText(field1, "xxx");
+        client.inputText(field2, "2");
+        
+        submit(submitButton);
+        
+        processLifecycleExecute();
+        processRender();
+
+        submitButton = facesContext.getViewRoot().findComponent("mainForm:submit:button");
+        field1 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field1");
+        field2 = (UIInput) facesContext.getViewRoot().findComponent("mainForm:field2");
+
+        Assert.assertEquals("Hello", field1.getValue());
+        Assert.assertEquals(1, field2.getValue());
+
+    }
 }

Copied: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_3.xhtml
(from r1520036, myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_2.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_3.xhtml?p2=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_3.xhtml&p1=myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_2.xhtml&r1=1520036&r2=1520154&rev=1520154&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_2.xhtml
(original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resetValuesActionListener_3.xhtml
Wed Sep  4 22:15:38 2013
@@ -16,14 +16,15 @@
 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
-             xmlns:ui="http://java.sun.com/jsf/facelets">
+             xmlns:ui="http://java.sun.com/jsf/facelets"
+             xmlns:test="http://java.sun.com/jsf/composite/test">
     <h:form id="mainForm">
         <h:inputText id="field1" value="#{bean.field1}">
             <f:validateLength minimum="4"/>
         </h:inputText>
         <h:inputText id="field2" value="#{bean.field2}"/>
-        <h:commandButton id="submit" value="Submit">
-            <f:ajax resetValues="true" render="field1 mainForm:field2"/>
-        </h:commandButton>
+        <test:simpleButton id="submit" value="Submit" immediate="true">
+            <f:resetValues render="field1 mainForm:field2" for="button"/>
+        </test:simpleButton>
     </h:form>
 </ui:composition>
\ No newline at end of file

Propchange: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/simpleButton.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/simpleButton.xhtml?rev=1520154&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/simpleButton.xhtml
(added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/simpleButton.xhtml
Wed Sep  4 22:15:38 2013
@@ -0,0 +1,32 @@
+<!--
+ 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.
+
+ $Id: defineInclude.xml 804043 2009-08-13 22:08:44Z lu4242 $
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:composite="http://java.sun.com/jsf/composite">
+<head>
+</head>
+<body>
+<composite:interface>
+    <composite:actionSource name="button"/>
+    <composite:attribute name="immediate" default="false"/>
+</composite:interface>
+<composite:implementation>
+    <h:commandButton id="button" value="Submit" immediate="#{cc.attrs.immediate}"/>
+</composite:implementation>
+</body>
+</html>
\ No newline at end of file

Propchange: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/jsf/core/reset/resources/test/simpleButton.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message