myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject [myfaces] branch master updated: MYFACES-4283
Date Sun, 03 Mar 2019 20:28:04 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 04073fb  MYFACES-4283
04073fb is described below

commit 04073fb6efbcdaeb1ca0fd25cd7675bef855d091
Author: Thomas Andraschko <tandraschko@apache.org>
AuthorDate: Sun Mar 3 21:27:57 2019 +0100

    MYFACES-4283
---
 .../main/java/javax/faces/component/UIForm.java    | 14 +++++++
 .../faces/component/InvokeOnComponentTest.java     | 44 ++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/api/src/main/java/javax/faces/component/UIForm.java b/api/src/main/java/javax/faces/component/UIForm.java
index 4b4f963..ce1f1d4 100755
--- a/api/src/main/java/javax/faces/component/UIForm.java
+++ b/api/src/main/java/javax/faces/component/UIForm.java
@@ -282,6 +282,20 @@ public class UIForm extends UIComponentBase implements NamingContainer,
UniqueId
     }
     
     @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)
     {
         if (!isPrependId())
diff --git a/impl/src/test/java/javax/faces/component/InvokeOnComponentTest.java b/impl/src/test/java/javax/faces/component/InvokeOnComponentTest.java
index 7776869..ef5a2f5 100644
--- a/impl/src/test/java/javax/faces/component/InvokeOnComponentTest.java
+++ b/impl/src/test/java/javax/faces/component/InvokeOnComponentTest.java
@@ -20,6 +20,8 @@ package javax.faces.component;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.faces.context.FacesContext;
 
 import javax.faces.model.DataModel;
 import javax.faces.model.ListDataModel;
@@ -55,6 +57,48 @@ 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();


Mime
View raw message