You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2019/03/03 20:32:21 UTC

[myfaces] branch 2.3.x updated: MYFACES-4283

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3.x by this push:
     new 5ef495a  MYFACES-4283
5ef495a is described below

commit 5ef495ac6f3b2d9b40a437702b7ff20a1b8d2cd1
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Sun Mar 3 21:32:17 2019 +0100

    MYFACES-4283
---
 .../main/java/javax/faces/component/UIForm.java    | 16 +++++++-
 .../faces/component/InvokeOnComponentTest.java     | 45 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/api/src/main/java/javax/faces/component/UIForm.java b/api/src/main/java/javax/faces/component/UIForm.java
index ad628a0..2754489 100755
--- a/api/src/main/java/javax/faces/component/UIForm.java
+++ b/api/src/main/java/javax/faces/component/UIForm.java
@@ -282,7 +282,21 @@ public class UIForm extends UIComponentBase implements NamingContainer, UniqueId
          uniqueIdCounter,
          submitted,
     }
-    
+
+    @Override
+    public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback) throws FacesException {
+        if (isPrependId()) {
+            String baseClientId = getClientId(context);
+
+            // skip if the component is not a children of the UIForm
+            if (!clientId.startsWith(baseClientId)) {
+                return false;
+            }
+        }
+
+        return super.invokeOnComponent(context, clientId, callback);
+    }
+
     @Override
     public boolean visitTree(VisitContext context, VisitCallback callback)
     {
diff --git a/api/src/test/java/javax/faces/component/InvokeOnComponentTest.java b/api/src/test/java/javax/faces/component/InvokeOnComponentTest.java
index 7776869..be79ce0 100644
--- a/api/src/test/java/javax/faces/component/InvokeOnComponentTest.java
+++ b/api/src/test/java/javax/faces/component/InvokeOnComponentTest.java
@@ -20,9 +20,11 @@ package javax.faces.component;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.faces.model.DataModel;
 import javax.faces.model.ListDataModel;
+import static junit.framework.TestCase.assertTrue;
 
 import org.apache.myfaces.dummy.data.Data;
 import org.jmock.Mock;
@@ -55,6 +57,49 @@ public class InvokeOnComponentTest extends AbstractComponentTest
         super.tearDown();
     }
 
+
+    public void testInvokeOnFormPrependId() throws Exception
+    {
+        UIForm form = new UIForm();
+        form.setId("form");
+        form.setPrependId(true);
+        facesContext.getViewRoot().getChildren().add(form);
+        
+        UIInput child1 = new UIInput();
+        child1.setId("child1");
+        form.getChildren().add(child1);
+
+        
+        AtomicBoolean val = new AtomicBoolean(false);
+        
+        this.facesContext.getViewRoot().invokeOnComponent(facesContext, "form:child1", (context, target) -> {
+            val.set(true);
+        });
+        
+        assertTrue(val.get());
+    }
+    
+    public void testInvokeOnFormPrependIdFalse() throws Exception
+    {
+        UIForm form = new UIForm();
+        form.setId("form");
+        form.setPrependId(false);
+        facesContext.getViewRoot().getChildren().add(form);
+        
+        UIInput child1 = new UIInput();
+        child1.setId("child1");
+        form.getChildren().add(child1);
+
+        
+        AtomicBoolean val = new AtomicBoolean(false);
+        
+        this.facesContext.getViewRoot().invokeOnComponent(facesContext, "child1", (context, target) -> {
+            val.set(true);
+        });
+        
+        assertTrue(val.get());
+    }
+    
     public void atestInvokeOnComp() throws Exception
     {
         UIForm form = new UIForm();