You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/05/27 22:04:02 UTC
git commit: Closes TAP5-2331 : Can't stop tapestry generating
clientId for fields
Repository: tapestry-5
Updated Branches:
refs/heads/master 339288142 -> d3a7a6da7
Closes TAP5-2331 : Can't stop tapestry generating clientId for fields
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/d3a7a6da
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/d3a7a6da
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/d3a7a6da
Branch: refs/heads/master
Commit: d3a7a6da7cabcf740cb0f29b6c71b959ab320ffc
Parents: 3392881
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Tue May 27 17:03:42 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Tue May 27 17:03:42 2014 -0300
----------------------------------------------------------------------
.../tapestry5/corelib/base/AbstractField.java | 11 +++--
.../app1/FormFieldClientIdParameterDemo.tml | 26 +++++++++++
.../tapestry5/integration/app1/FormTests.java | 23 ++++++++++
.../pages/FormFieldClientIdParameterDemo.java | 46 ++++++++++++++++++++
.../tapestry5/integration/app1/pages/Index.java | 3 +-
5 files changed, 104 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3a7a6da/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
index 7600709..2c9fa9d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
@@ -115,9 +115,12 @@ public abstract class AbstractField implements Field
private static final ProcessSubmission PROCESS_SUBMISSION_ACTION = new ProcessSubmission();
/**
- * The id used to generate a page-unique client-side identifier for the component. If a component renders multiple
- * times, a suffix will be appended to the to id to ensure uniqueness. The uniqued value may be accessed via the
- * {@link #getClientId() clientId property}.
+ * The id used to generate a page-unique client-side identifier for the component. If this parameter is not bound
+ * and a component renders multiple times, a suffix will be appended to the to id to ensure uniqueness. Either way,
+ * its value may be accessed via the {@link #getClientId() clientId property}.
+ * When this parameter is bound, Tapestry considers the user (developer) is taking care of
+ * providing unique client-side identifiers. Special care should be taken when the
+ * field is inside a Zone.
*/
@Parameter(value = "prop:componentResources.id", defaultPrefix = BindingConstants.LITERAL)
protected String clientId;
@@ -174,7 +177,7 @@ public abstract class AbstractField implements Field
throw new RuntimeException(String.format("Component %s must be enclosed by a Form component.",
resources.getCompleteId()));
- assignedClientId = javaScriptSupport.allocateClientId(id);
+ assignedClientId = resources.isBound("clientId") ? clientId : javaScriptSupport.allocateClientId(id);
String controlName = formSupport.allocateControlName(id);
formSupport.storeAndExecute(this, new Setup(controlName));
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3a7a6da/tapestry-core/src/test/app1/FormFieldClientIdParameterDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/FormFieldClientIdParameterDemo.tml b/tapestry-core/src/test/app1/FormFieldClientIdParameterDemo.tml
new file mode 100644
index 0000000..b2bdac6
--- /dev/null
+++ b/tapestry-core/src/test/app1/FormFieldClientIdParameterDemo.tml
@@ -0,0 +1,26 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
+
+ <h1>Form Field clientId Parameter Demo</h1>
+
+ <p>Without explicit client id</p>
+
+ <t:zone t:id="zone">
+
+ <t:form t:zone="zone">
+ <t:loop source="source">
+ <t:textfield t:id="textfield" value="string" />
+ </t:loop>
+ </t:form>
+
+ <p>With explicit client id</p>
+ <t:form>
+ <t:loop source="source" index="index">
+ <t:textfield t:id="textfieldWithClientId" value="string" clientId="prop:clientId" />
+ </t:loop>
+ </t:form>
+
+ <t:eventlink event="updateZone" zone="zone" id="updateZone">Update zone</t:eventlink>
+
+ </t:zone>
+
+</html>
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3a7a6da/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
index 15b3af5..9df7a1c 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FormTests.java
@@ -1167,4 +1167,27 @@ public class FormTests extends App1TestCase
assertTextPresent("entity.id: [2]");
}
+
+ /** TAP5-2331 */
+ @Test
+ public void form_fields_client_id_parameter()
+ {
+ final String[] clientIds = {"clientId-0", "clientId-1"};
+
+ openLinks("Form Field clientId Parameter Demo");
+
+ for (int i = 0; i < 4; i++) {
+
+ for (String clientId : clientIds)
+ {
+ assertTrue(selenium.isElementPresent(clientId));
+ }
+
+ click("updateZone");
+ waitForAjaxRequestsToComplete();
+
+ }
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3a7a6da/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldClientIdParameterDemo.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldClientIdParameterDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldClientIdParameterDemo.java
new file mode 100644
index 0000000..96e655e
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldClientIdParameterDemo.java
@@ -0,0 +1,46 @@
+// Copyright 2014 The Apache Software Foundation
+//
+// 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.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.corelib.components.Zone;
+
+public class FormFieldClientIdParameterDemo
+{
+ public final static int ITERATIONS = 2;
+
+ @Property
+ private String string;
+
+ @Property
+ private int index;
+
+ @InjectComponent
+ private Zone zone;
+
+ public int[] getSource() {
+ return new int[ITERATIONS]; // values itself don't matter, just length of array
+ }
+
+ public String getClientId() {
+ return "clientId-" + index;
+ }
+
+ Object onUpdateZone() {
+ return zone.getBody();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/d3a7a6da/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
index 99f2a16..bcaae7b 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
@@ -568,8 +568,9 @@ public class Index
new Item("inplacegridinloopdemo", "In-Place Grid in a Loop Demo", "In-place grid in a loop"),
- new Item("GenericTypeDemo", "Generic bound type demo", "Tests that generic type info is available for generic bindings")
+ new Item("GenericTypeDemo", "Generic bound type demo", "Tests that generic type info is available for generic bindings"),
+ new Item("FormFieldClientIdParameterDemo", "Form Field clientId Parameter Demo", "Shows and tests how to explicitly set the id of a form field component")
);
static