You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2017/09/17 12:30:49 UTC
[myfaces-trinidad] 26/36: Fix setId() to clear the cached clientId
at the end of the function so that the code that checks whether we have a
cached clientId works correctly Add tests for the basic cases where a
cached clientId needs to be cleared--setting the id of a NamingContainer
(clear subtree),
setting the id of a component (clear component's cached clientId),
move component between NamingContainers (clear subtree)
This is an automated email from the ASF dual-hosted git repository.
deki pushed a commit to branch 1.2.12.2-branch
in repository https://gitbox.apache.org/repos/asf/myfaces-trinidad.git
commit 433da04aac0111da452448551e817bc543daa853
Author: Blake Sullivan <bs...@apache.org>
AuthorDate: Wed Mar 3 01:01:13 2010 +0000
Fix setId() to clear the cached clientId at the end of the function so that the code that checks whether we have a cached clientId works correctly
Add tests for the basic cases where a cached clientId needs to be cleared--setting the id of a NamingContainer (clear subtree), setting the id of a component (clear component's cached clientId), move component between NamingContainers (clear subtree)
---
.../trinidad/component/UIXComponentBase.java | 6 +-
.../trinidad/component/ClientIdCachingTest.java | 143 +++++++++++++++++++++
2 files changed, 147 insertions(+), 2 deletions(-)
diff --git a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
index ff71c3f..335c8f8 100644
--- a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
+++ b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
@@ -362,7 +362,9 @@ abstract public class UIXComponentBase extends UIXComponent
clientId = _calculateClientId(context);
if (_usesFacesBeanImpl)
+ {
_clientId = clientId;
+ }
}
else
{
@@ -436,8 +438,6 @@ abstract public class UIXComponentBase extends UIXComponent
@Override
public void setId(String id)
{
- _clientId = null;
-
FacesBean facesBean = getFacesBean();
// if we are using a FacesBeanImpl, then the FacesBean will
@@ -465,6 +465,8 @@ abstract public class UIXComponentBase extends UIXComponent
_validateId(id);
facesBean.setProperty(ID_KEY, id);
}
+
+ _clientId = null;
}
@Override
diff --git a/trinidad-api/src/test/java/org/apache/myfaces/trinidad/component/ClientIdCachingTest.java b/trinidad-api/src/test/java/org/apache/myfaces/trinidad/component/ClientIdCachingTest.java
new file mode 100644
index 0000000..aa46806
--- /dev/null
+++ b/trinidad-api/src/test/java/org/apache/myfaces/trinidad/component/ClientIdCachingTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.trinidad.component;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.context.FacesContext;
+import javax.faces.render.Renderer;;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.trinidadbuild.test.FacesTestCase;
+
+import org.apache.myfaces.trinidad.component.UIXPanel;
+
+public class ClientIdCachingTest extends FacesTestCase
+{
+ public static final Test suite()
+ {
+ return new TestSuite(ClientIdCachingTest.class);
+ }
+
+ public static void main(String[] args) throws Throwable
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public ClientIdCachingTest(
+ String testName)
+ {
+ super(testName);
+ }
+
+ static private class TestPanel extends UIXPanel
+ {
+ protected Renderer getRenderer(FacesContext context)
+ {
+ return null;
+ }
+ }
+
+ static private class TestNamingContainer extends TestPanel
+ implements NamingContainer
+ {
+ }
+
+ // Test nested NamingContainer callbacks
+ @SuppressWarnings("unchecked")
+ public void testBasic()
+ {
+ TestNamingContainer a = new TestNamingContainer(); a.setId("a");
+ TestNamingContainer b = new TestNamingContainer(); b.setId("b");
+ TestNamingContainer d = new TestNamingContainer(); d.setId("d");
+ TestPanel e = new TestPanel(); e.setId("e");
+ TestPanel g = new TestPanel(); g.setId("g");
+ a.getChildren().add(b);
+ b.getChildren().add(d);
+ b.getChildren().add(g);
+ d.getChildren().add(e);
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ assertEquals("a:b:d:e", e.getClientId(context));
+ }
+
+ public void testSetId()
+ {
+ TestNamingContainer a = new TestNamingContainer(); a.setId("a");
+ TestNamingContainer b = new TestNamingContainer(); b.setId("b");
+ TestNamingContainer d = new TestNamingContainer(); d.setId("d");
+ TestPanel e = new TestPanel(); e.setId("e");
+ TestPanel g = new TestPanel(); g.setId("g");
+ a.getChildren().add(b);
+ b.getChildren().add(d);
+ b.getChildren().add(g);
+ d.getChildren().add(e);
+
+ // prime
+ FacesContext context = FacesContext.getCurrentInstance();
+ assertEquals("a:b:d:e", e.getClientId(context));
+
+ // set the component's id using accessor
+ e.setId("ePrime");
+ assertEquals("a:b:d:ePrime", e.getClientId(context));
+
+ // set the component's id using attribute map
+ e.getAttributes().put("id", "eDoublePrime");
+ assertEquals("a:b:d:eDoublePrime", e.getClientId(context));
+
+
+ // set an ancsestor's id using accessor
+ b.setId("bPrime");
+ assertEquals("a:bPrime:d:eDoublePrime", e.getClientId(context));
+
+ // set the component's id using attribute map
+ b.getAttributes().put("id", "bDoublePrime");
+ assertEquals("a:bDoublePrime:d:eDoublePrime", e.getClientId(context));
+ }
+
+ public void testMoving()
+ {
+ TestNamingContainer a = new TestNamingContainer(); a.setId("a");
+ TestNamingContainer b = new TestNamingContainer(); b.setId("b");
+ TestNamingContainer c = new TestNamingContainer(); c.setId("c");
+ TestNamingContainer d = new TestNamingContainer(); d.setId("d");
+ TestPanel e = new TestPanel(); e.setId("e");
+ TestPanel f = new TestPanel(); f.setId("f");
+ TestPanel g = new TestPanel(); g.setId("g");
+ a.getChildren().add(b);
+ a.getChildren().add(c);
+ b.getChildren().add(d);
+ b.getChildren().add(g);
+ d.getChildren().add(e);
+ d.getChildren().add(f);
+
+ // prime
+ FacesContext context = FacesContext.getCurrentInstance();
+ assertEquals("a:b:d:e", e.getClientId(context));
+
+ // move within same NamingContainer--no clientId change
+ f.getChildren().add(e);
+ assertEquals("a:b:d:e", e.getClientId(context));
+
+ // move between NamingContainers
+ g.getChildren().add(e);
+ assertEquals("a:b:e", e.getClientId(context));
+ }
+}
--
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.