You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/10/23 01:21:20 UTC
[6/6] git commit: Restore missing in-place Grid behavior
Restore missing in-place Grid behavior
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/fc9e7b0e
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/fc9e7b0e
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/fc9e7b0e
Branch: refs/heads/5.4-js-rewrite
Commit: fc9e7b0eb87eb483c466b9e350a2e0dfd1862e10
Parents: 6d6c1eb
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Oct 22 14:21:11 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Oct 22 14:21:37 2012 -0700
----------------------------------------------------------------------
.../coffeescript/META-INF/modules/core/grid.coffee | 32 +++++++
.../apache/tapestry5/corelib/components/Grid.java | 67 +++++++--------
.../tapestry5/corelib/components/GridColumns.java | 48 ++++++-----
.../tapestry5/corelib/components/GridPager.java | 62 ++++++--------
.../apache/tapestry5/corelib/components/Grid.tml | 4 +-
.../tapestry5/corelib/components/GridColumns.tml | 2 +-
6 files changed, 116 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fc9e7b0e/tapestry-core/src/main/coffeescript/META-INF/modules/core/grid.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/grid.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/grid.coffee
new file mode 100644
index 0000000..e098e00
--- /dev/null
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/grid.coffee
@@ -0,0 +1,32 @@
+# Copyright 2012 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.
+
+
+# ##core/grid
+#
+# Adds support for in-place updates of the Grid component. The Grid renders a
+# div[data-zone] around the table, and code here intercepts clicks on links that
+# are inside a div[data-inplace-grid-links].
+#
+define ["core/spi", "core/events"], (spi, events) ->
+
+ spi.onDocument "[data-inplace-grid-links] a", ->
+
+ zone = this.findContainer "[data-zone]"
+
+ zone.trigger events.zone.refresh, url: a.getAttribute "href"
+
+ return false
+
+ return null
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fc9e7b0e/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
index 2fddc09..d417a43 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010, 2011, 2012 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.
@@ -14,37 +14,27 @@
package org.apache.tapestry5.corelib.components;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-
import org.apache.tapestry5.*;
-import org.apache.tapestry5.annotations.Component;
-import org.apache.tapestry5.annotations.Environmental;
-import org.apache.tapestry5.annotations.Parameter;
-import org.apache.tapestry5.annotations.Persist;
-import org.apache.tapestry5.annotations.Property;
-import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.beaneditor.PropertyModel;
import org.apache.tapestry5.corelib.data.GridPagerPosition;
-import org.apache.tapestry5.grid.ColumnSort;
-import org.apache.tapestry5.grid.GridDataSource;
-import org.apache.tapestry5.grid.GridModel;
-import org.apache.tapestry5.grid.GridSortModel;
-import org.apache.tapestry5.grid.SortConstraint;
+import org.apache.tapestry5.grid.*;
import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.internal.beaneditor.BeanModelUtils;
import org.apache.tapestry5.internal.bindings.AbstractBinding;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.services.BeanModelSource;
-import org.apache.tapestry5.services.ClientBehaviorSupport;
import org.apache.tapestry5.services.ComponentDefaultProvider;
import org.apache.tapestry5.services.ComponentEventResultProcessor;
import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
/**
* A grid presents tabular data. It is a composite component, created in terms of several sub-components. The
* sub-components are statically wired to the Grid, as it provides access to the data and other models that they need.
@@ -60,11 +50,11 @@ import org.apache.tapestry5.services.javascript.JavaScriptSupport;
* encoder parameter), or use an entity type for the "row" parameter for which
* Tapestry can provide a ValueEncoder automatically. This will allow Tapestry
* to use a unique ID for each row that doesn't change when rows are reordered.
- *
+ *
+ * @tapestrydoc
* @see org.apache.tapestry5.beaneditor.BeanModel
* @see org.apache.tapestry5.services.BeanModelSource
* @see org.apache.tapestry5.grid.GridDataSource
- * @tapestrydoc
* @see BeanEditForm
* @see BeanDisplay
* @see Loop
@@ -199,14 +189,16 @@ public class Grid implements GridModel
/**
* If true, then the Grid will be wrapped in an element that acts like a
* {@link org.apache.tapestry5.corelib.components.Zone}; all the paging and sorting links will refresh the zone,
- * repainting
- * the entire grid within it, but leaving the rest of the page (outside the zone) unchanged.
+ * repainting the entire grid within it, but leaving the rest of the page (outside the zone) unchanged.
*/
@Parameter
private boolean inPlace;
/**
- * The name of the psuedo-zone that encloses the Grid.
+ * The name of the psuedo-zone that encloses the Grid. Starting in 5.4, this is always either
+ * null or "^" and is not really used the way it was in 5.3; instead it triggerers the addition
+ * of a {@code data-inplace-grid-links} attribute in a div surrounding any links related to
+ * sorting or pagination. The rest is sorted out on the client. See module {@code core/grid}.
*/
@Property(write = false)
private String zone;
@@ -229,19 +221,19 @@ public class Grid implements GridModel
private BeanModelSource modelSource;
@Environmental
- private ClientBehaviorSupport clientBehaviorSupport;
+ private JavaScriptSupport javaScriptSupport;
@Component(parameters =
- { "index=inherit:columnIndex", "lean=inherit:lean", "overrides=overrides", "zone=zone" })
+ {"index=inherit:columnIndex", "lean=inherit:lean", "overrides=overrides", "zone=zone"})
private GridColumns columns;
@Component(parameters =
- { "columnIndex=inherit:columnIndex", "rowsPerPage=rowsPerPage", "currentPage=currentPage", "row=row",
- "overrides=overrides" }, publishParameters = "rowIndex,rowClass,volatile,encoder,lean")
+ {"columnIndex=inherit:columnIndex", "rowsPerPage=rowsPerPage", "currentPage=currentPage", "row=row",
+ "overrides=overrides"}, publishParameters = "rowIndex,rowClass,volatile,encoder,lean")
private GridRows rows;
@Component(parameters =
- { "source=dataSource", "rowsPerPage=rowsPerPage", "currentPage=currentPage", "zone=zone" })
+ {"source=dataSource", "rowsPerPage=rowsPerPage", "currentPage=currentPage", "zone=zone"})
private GridPager pager;
@Component(parameters = "to=pagerTop")
@@ -256,9 +248,6 @@ public class Grid implements GridModel
@Environmental(false)
private FormSupport formSupport;
- @Environmental
- private JavaScriptSupport jsSupport;
-
/**
* Defines where block and label overrides are obtained from. By default, the Grid component provides block
* overrides (from its block parameters).
@@ -383,7 +372,7 @@ public class Grid implements GridModel
* Returns a {@link org.apache.tapestry5.Binding} instance that attempts to identify the model from the source
* parameter (via {@link org.apache.tapestry5.grid.GridDataSource#getRowType()}. Subclasses may override to provide
* a different mechanism. The returning binding is variant (not invariant).
- *
+ *
* @see BeanModelSource#createDisplayModel(Class, org.apache.tapestry5.ioc.Messages)
*/
protected Binding defaultModel()
@@ -493,13 +482,17 @@ public class Grid implements GridModel
if (inPlace && zone == null)
{
- zone = jsSupport.allocateClientId(resources);
-
- writer.element("div", "id", zone);
+ javaScriptSupport.require("core/zone");
+ javaScriptSupport.require("core/grid");
- clientBehaviorSupport.addZone(zone, null, "show");
+ writer.element("div", "data-zone", "true");
didRenderZoneDiv = true;
+
+ // Through Tapestry 5.3, we had a specific id for the zone that had to be passed down to the
+ // GridPager and etc. That's no longer necessary, so zone will always be null or "^". We don't
+ // even need any special ids to be allocated!
+ zone = "^";
}
return null;
@@ -598,9 +591,9 @@ public class Grid implements GridModel
* {@link org.apache.tapestry5.services.ComponentEventResultProcessor#processResultValue(Object)} passing this (the
* Grid component) as the content provider for the update.
*/
- void onInPlaceUpdate(String zone) throws IOException
+ void onInPlaceUpdate() throws IOException
{
- this.zone = zone;
+ this.zone = "^";
componentEventResultProcessor.processResultValue(this);
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fc9e7b0e/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
index f3e4bd8..c53df86 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridColumns.java
@@ -26,12 +26,13 @@ import org.apache.tapestry5.internal.TapestryInternalUtils;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.services.Request;
import java.util.List;
/**
* Renders out the column headers for the grid, including links (where appropriate) to control column sorting.
- *
+ *
* @tapestrydoc
*/
@SupportsInformalParameters
@@ -65,10 +66,12 @@ public class GridColumns
@Parameter
private String zone;
+ // TODO: Two EventLinks just to suppress the space between the text and the icon is not very modern.
+ // Use the CSS, Luke!
@SuppressWarnings("unused")
@Component(
- parameters = { "event=sort", "disabled=sortDisabled", "context=columnContext", "class=sortLinkClass",
- "zone=inherit:zone" })
+ parameters = {"event=sort", "disabled=sortDisabled", "context=columnModel.id", "class=sortLinkClass",
+ "zone=inherit:zone"})
private EventLink sort, sort2;
@Inject
@@ -107,6 +110,9 @@ public class GridColumns
@Inject
private ComponentResources resources;
+ @Inject
+ private Request request;
+
void setupRender()
{
lastColumnIndex = gridModel.getDataModel().getPropertyNames().size() - 1;
@@ -167,25 +173,19 @@ public class GridColumns
* Normal, non-Ajax event handler.
*/
- void onSort(String columnId)
+ boolean onSort(String columnId)
{
gridModel.getSortModel().updateSort(columnId);
- }
-
- /**
- * Ajax event handler, which carries the zone id.
- */
- boolean onSort(String columnId, String zone)
- {
- onSort(columnId);
-
- resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, new Object[] { zone }, null);
- // Event is handled, don't trigger further event handler methods.
+ if (request.isXHR())
+ {
+ resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, null, null);
+ }
return true;
}
+
public Asset getIcon()
{
switch (getSortForColumn())
@@ -201,13 +201,6 @@ public class GridColumns
}
}
- public Object getColumnContext()
- {
- if (zone == null) return columnModel.getId();
-
- return new Object[] { columnModel.getId(), zone };
- }
-
public String getIconLabel()
{
switch (getSortForColumn())
@@ -241,4 +234,15 @@ public class GridColumns
return standardHeader;
}
+
+ /**
+ * Returns null or "true", depending on whether the Grid is rendering for in-place updates or not ("true"
+ * means in-place updates). The affects whether the data-inplace-grid-links attribute will be rendered or not.
+ *
+ * @return
+ */
+ public String getInplaceGridLinks()
+ {
+ return zone == null ? null : "true";
+ }
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fc9e7b0e/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
index 49bf819..229a079 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridPager.java
@@ -15,7 +15,6 @@
package org.apache.tapestry5.corelib.components;
import org.apache.tapestry5.*;
-import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Events;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.dom.Element;
@@ -23,8 +22,7 @@ import org.apache.tapestry5.grid.GridDataSource;
import org.apache.tapestry5.internal.InternalConstants;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.services.ClientBehaviorSupport;
-import org.apache.tapestry5.services.javascript.JavaScriptSupport;
+import org.apache.tapestry5.services.Request;
/**
* Generates a series of links used to jump to a particular page index within the overall data set.
@@ -76,11 +74,8 @@ public class GridPager
@Inject
private Messages messages;
- @Environmental
- private ClientBehaviorSupport clientBehaviorSupport;
-
- @Environmental
- private JavaScriptSupport jsSupport;
+ @Inject
+ private Request request;
void beginRender(MarkupWriter writer)
{
@@ -91,6 +86,12 @@ public class GridPager
if (maxPages < 2) return;
writer.element("div", "class", "pagination");
+
+ if (zone != null)
+ {
+ writer.attributes("data-inplace-grid-links", true);
+ }
+
writer.element("ul");
lastIndex = 0;
@@ -130,7 +131,8 @@ public class GridPager
if (pageIndex <= lastIndex) return;
- if (pageIndex != lastIndex + 1) {
+ if (pageIndex != lastIndex + 1)
+ {
writer.element("li", "class", "disabled");
writer.element("a", "href", "#");
writer.write(" ... ");
@@ -152,14 +154,16 @@ public class GridPager
writer.element("li");
- Object[] context = zone == null
- ? new Object[]{pageIndex}
- : new Object[]{pageIndex, zone};
+ Link link = resources.createEventLink(EventConstants.ACTION, pageIndex);
- Link link = resources.createEventLink(EventConstants.ACTION, context);
+ if (zone != null)
+ {
+ link.addParameter("t:inplace", "true");
+ }
Element element = writer.element("a",
- "href", zone == null ? link : "#",
+ "href", link,
+ "data-update-zone", zone,
"title", messages.format("core-goto-page", pageIndex));
@@ -168,38 +172,22 @@ public class GridPager
writer.end();
writer.end(); // li
-
- if (zone != null)
- {
- String id = jsSupport.allocateClientId(resources);
-
- element.attribute("id", id);
-
- clientBehaviorSupport.linkZone(id, zone, link);
- }
-
-
}
/**
- * Normal, non-Ajax event handler.
+ * Repaging event handler.
*/
- void onAction(int newPage)
+ boolean onAction(int newPage)
{
// TODO: Validate newPage in range
currentPage = newPage;
- }
- /**
- * Akjax event handler, passing the zone along.
- */
- boolean onAction(int newPage, String zone)
- {
- onAction(newPage);
-
- resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, new Object[]{zone}, null);
+ if (request.isXHR())
+ {
+ resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, null, null);
+ }
- return true; // abort event
+ return true; // abort event
}
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fc9e7b0e/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Grid.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Grid.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Grid.tml
index 3fd891a..e4513ee 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Grid.tml
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Grid.tml
@@ -1,4 +1,4 @@
-<div class="t-data-grid" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
<div t:id="pagerTop"/>
@@ -17,4 +17,4 @@
<t:block id="empty">${message:core-no-grid-data-to-display}</t:block>
-</div>
+</t:container>
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/fc9e7b0e/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
index 334c173..74f9bd1 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridColumns.tml
@@ -1,5 +1,5 @@
<thead xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xml:space="default">
- <tr>
+ <tr data-inplace-grid-links="${inplaceGridLinks}">
<th t:type="Loop" source="columnNames" value="columnName" formstate="none" class="prop:headerClass"
index="index">
<t:delegate to="blockForColumn"/>