TAP5-2308: allocate then FormFragment's client ID when it is first requested
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
index ad6ea47..2ee623f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormFragment.java
@@ -156,7 +156,7 @@
{
FormSupport formSupport = environment.peekRequired(FormSupport.class);
- clientId = resources.isBound("id") ? idParameter : javascriptSupport.allocateClientId(resources);
+ String clientId = getClientId();
hiddenFieldPositioner = new HiddenFieldPositioner(writer, rules);
@@ -241,6 +241,10 @@
public String getClientId()
{
+ if (clientId == null)
+ {
+ clientId = resources.isBound("id") ? idParameter : javascriptSupport.allocateClientId(resources);
+ }
return clientId;
}
}
diff --git a/tapestry-core/src/test/app1/BeanEditorWithFormFragmentDemo.tml b/tapestry-core/src/test/app1/BeanEditorWithFormFragmentDemo.tml
new file mode 100644
index 0000000..3d8b8dc
--- /dev/null
+++ b/tapestry-core/src/test/app1/BeanEditorWithFormFragmentDemo.tml
@@ -0,0 +1,19 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd" xmlns:p="tapestry:parameter">
+<h1>Bean Editor With Form Fragment Demo</h1>
+
+ <t:form>
+ <t:beaneditor object="job"
+ include="title,canBeDoneRemotely">
+ <p:canBeDoneRemotely>
+ <t:checkbox t:id="canBeDoneRemotely" value="job.canBeDoneRemotely"
+ t:mixins="triggerfragment" TriggerFragment.fragment="jobAddress" TriggerFragment.invert="true"/>
+ <t:label for="canBeDoneRemotely" />
+ </p:canBeDoneRemotely>
+ </t:beaneditor>
+
+ <t:formfragment t:id="jobAddress" visible="!job.canBeDoneRemotely">
+ <t:beaneditor object="job" include="address" />
+ </t:formfragment>
+ </t:form>
+
+</html>
\ No newline at end of file
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/BeanEditorWithFormFragmentTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/BeanEditorWithFormFragmentTests.groovy
new file mode 100644
index 0000000..0c81d15
--- /dev/null
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/BeanEditorWithFormFragmentTests.groovy
@@ -0,0 +1,21 @@
+package org.apache.tapestry5.integration.app1
+
+import org.apache.tapestry5.integration.GroovyTapestryCoreTestCase
+import org.apache.tapestry5.test.TapestryTestConfiguration
+import org.testng.annotations.Test
+
+@TapestryTestConfiguration(webAppFolder = "src/test/app1")
+class BeanEditorWithFormFragmentTests extends GroovyTapestryCoreTestCase
+{
+
+ /** TAP5-2308 */
+ @Test
+ void beaneditor_with_formfragment_and_triggerfragment_mixin()
+ {
+ open "/BeanEditorWithFormFragmentDemo"
+ assert isVisible("css=#address")
+ click "css=#canBeDoneRemotely"
+ assert !isVisible("css=#address")
+ }
+
+}
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorWithFormFragmentDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorWithFormFragmentDemo.java
new file mode 100644
index 0000000..88ccbed
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BeanEditorWithFormFragmentDemo.java
@@ -0,0 +1,42 @@
+// Copyright 2008, 2010 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.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.annotations.SetupRender;
+
+public class BeanEditorWithFormFragmentDemo {
+ @Persist
+ @Property
+ private Job job;
+
+ @SetupRender
+ void initJob() {
+ if (job == null) {
+ job = new Job();
+ }
+ }
+
+ public static class Job {
+
+ public String title;
+
+ public boolean canBeDoneRemotely;
+
+ public String address;
+
+ }
+}
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 79aa58d..d7d76d6 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
@@ -600,7 +600,9 @@
"error event on submit when textfield is empty"),
new Item("onactivateredirect", "OnActivateRedirect Demo", "A page that redirects to itself from"
- + " its activation method")
+ + " its activation method"),
+
+ new Item("BeanEditorWithFormFragmentDemo", "Bean Editor With Form Fragment Demo", "TriggerFragment mixin used inside a BeanEditor")
);