You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2014/09/03 00:21:53 UTC
git commit: TAP5-2382: Use simple, not namespaced ids, in some Zones
Repository: tapestry-5
Updated Branches:
refs/heads/master d5f6a5928 -> 752e92e59
TAP5-2382: Use simple, not namespaced ids, in some Zones
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/752e92e5
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/752e92e5
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/752e92e5
Branch: refs/heads/master
Commit: 752e92e596b6aff55481ad9b1ae797882a747465
Parents: d5f6a59
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Sep 2 15:22:03 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Sep 2 15:22:03 2014 -0700
----------------------------------------------------------------------
.../META-INF/modules/t5/core/zone.coffee | 8 +++----
.../tapestry5/corelib/components/Zone.java | 23 ++++++++++++++++----
.../tapestry5/internal/InternalConstants.java | 9 ++++++++
.../tapestry5/modules/JavaScriptModule.java | 15 ++++++++++---
tapestry-core/src/test/app1/nested/ZoneDemo.tml | 2 +-
5 files changed, 45 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/752e92e5/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee
index 54e1a2f..5735ae8 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/zone.coffee
@@ -1,5 +1,3 @@
-# Copyright 2012, 2013 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
@@ -107,7 +105,7 @@ define ["./dom", "./events", "./ajax", "./console", "./forms", "underscore"],
dom.onDocument events.zone.refresh, (event) ->
- # This even may be triggered on an element inside the zone, rather than on the zone itself. Scan upwards
+ # This event may be triggered on an element inside the zone, rather than on the zone itself. Scan upwards
# to find the actual zone.
zone = @closest "[data-container-type=zone]"
@@ -116,8 +114,10 @@ define ["./dom", "./events", "./ajax", "./console", "./forms", "underscore"],
parameters = attr and JSON.parse attr
+ simpleIdParams = if zone.attr "data-simple-ids" then {"t:suppress-namespaced-ids": true}
+
ajax event.memo.url,
- data: _.extend { "t:zoneid": zone.element.id }, parameters, event.memo.parameters
+ data: _.extend { "t:zoneid": zone.element.id }, simpleIdParams, parameters, event.memo.parameters
success: (response) ->
zone.trigger events.zone.update, content: response.json?.content
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/752e92e5/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
index 5d68659..00f2016 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
@@ -1,5 +1,3 @@
-// Copyright 2007-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
@@ -116,6 +114,17 @@ public class Zone implements ClientBodyElement
@Parameter
private boolean visible;
+ /**
+ * if set to true, then Ajax updates related to this Zone will, when rending, use simple IDs (not namespaced ids).
+ * This is useful when the Zone contains a simple Form, as it (hopefully) ensures that the same ids used when
+ * initially rendering, and when processing the submission, are also used when re-rendering the Form (to present
+ * errors to the user). The default is false, maintaining the same behavior as in Tapestry 5.3 and earlier.
+ *
+ * @since 5.4
+ */
+ @Parameter
+ private boolean simpleIds;
+
@Inject
private ComponentResources resources;
@@ -167,6 +176,11 @@ public class Zone implements ClientBodyElement
"id", clientId,
"data-container-type", "zone");
+ if (simpleIds)
+ {
+ e.attribute("data-simple-ids", "true");
+ }
+
resources.renderInformalParameters(writer);
insideForm = formSupport != null;
@@ -247,10 +261,11 @@ public class Zone implements ClientBodyElement
{
if (resources.isBound("id"))
return idParameter;
-
+
// TAP4-2342. I know this won't work with a Zone with no given clientId and that was already
// via AJAX inside an outer Zone, but it's still better than nothing.
- if (clientId == null) {
+ if (clientId == null)
+ {
clientId = resources.getId();
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/752e92e5/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
index 7fa95e9..9ad6b7c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/InternalConstants.java
@@ -198,4 +198,13 @@ public final class InternalConstants
* @since 5.4
*/
public static final String REFERENCED_COMPONENT_NOT_FOUND = "tapestry.referenced-component-not-found";
+
+ /**
+ * Name of request parameter that suppresses the logic that injects a random-ish namespace into allocated ids when rending partial page
+ * responses. This, of course, requires a lot of testing to ensure that there are no resulting name classes,
+ * and should not be used inside Zones containing an {@link org.apache.tapestry5.corelib.components.AjaxFormLoop}.
+ *
+ * @since 5.4
+ */
+ public static final String SUPPRESS_NAMESPACED_IDS = "t:suppress-namespaced-ids";
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/752e92e5/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
index 6846e60..3dbab61 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
@@ -289,11 +289,20 @@ public class JavaScriptModule
{
public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer)
{
- String uid = Long.toHexString(System.nanoTime());
+ IdAllocator idAllocator;
- String namespace = "_" + uid;
+ if (request.getParameter(InternalConstants.SUPPRESS_NAMESPACED_IDS) == null)
+ {
+ String uid = Long.toHexString(System.nanoTime());
- IdAllocator idAllocator = new IdAllocator(namespace);
+ String namespace = "_" + uid;
+
+ idAllocator = new IdAllocator(namespace);
+ } else
+ {
+ // When suppressed, work just like normal rendering.
+ idAllocator = new IdAllocator();
+ }
DocumentLinker linker = environment.peekRequired(DocumentLinker.class);
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/752e92e5/tapestry-core/src/test/app1/nested/ZoneDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/nested/ZoneDemo.tml b/tapestry-core/src/test/app1/nested/ZoneDemo.tml
index cd4beaf..c9260ef 100644
--- a/tapestry-core/src/test/app1/nested/ZoneDemo.tml
+++ b/tapestry-core/src/test/app1/nested/ZoneDemo.tml
@@ -5,7 +5,7 @@
<h2>Last update: ${currentTime}</h2>
-<t:zone t:id="output" style="float:right; width: 800px;">
+<t:zone t:id="output" style="float:right; width: 800px;" simpleIds="true">
<t:if test="name" else="No name has been selected.">
Selected: ${name}
</t:if>