Updated Branches: refs/heads/master 4b5098271 -> dc342eb11
Change how the Grid component renders TH, TR, and TD elements to use data- attributes, not CSS class names Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/dc342eb1 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/dc342eb1 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/dc342eb1 Branch: refs/heads/master Commit: dc342eb116e775165bdac4a5de8f3f45fa0235e0 Parents: 4b50982 Author: Howard M. Lewis Ship <[email protected]> Authored: Tue Jun 18 17:03:37 2013 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Tue Jun 18 17:03:37 2013 -0700 ---------------------------------------------------------------------- 54_RELEASE_NOTES.txt | 3 + .../tapestry5/corelib/components/Grid.xdoc | 31 ++++++---- .../corelib/components/GridColumns.java | 54 +++++++---------- .../tapestry5/corelib/components/GridRows.java | 62 ++++++++++---------- .../corelib/components/GridColumns.tml | 27 ++++----- .../tapestry5/corelib/components/GridRows.tml | 5 +- tapestry-core/src/test/app1/GridDemo.tml | 6 +- .../symbolparam/GridSymbolDemoTests.groovy | 11 ++-- .../symbolparam/components/Layout.groovy | 4 +- .../tapestry5/integration/app1/GridTests.java | 19 +++--- 10 files changed, 113 insertions(+), 109 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/54_RELEASE_NOTES.txt ---------------------------------------------------------------------- diff --git a/54_RELEASE_NOTES.txt b/54_RELEASE_NOTES.txt index 28f7e40..e6eac18 100644 --- a/54_RELEASE_NOTES.txt +++ b/54_RELEASE_NOTES.txt @@ -275,3 +275,6 @@ Where Tapestry-specific CSS still exists (in support of the Palette component an has been removed. This may affect applications that overrode the Tapestry CSS rules to adapt Tapestry to the application look and feel. +The Grid component no longer emits CSS class names, instead it renders data attributes into Grid headers, rows, and cells, +such as `data-grid-row=first`, `data-grid-property=title`, etc. These attributes may still be referenced using CSS rules +where desired. http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.xdoc ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.xdoc b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.xdoc index c0677af..dc2260f 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.xdoc +++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Grid.xdoc @@ -251,42 +251,49 @@ delete-label=Delete user?]]></source> <p>The Grid component is designed to be customized via CSS. As it renders <th>, <tr> and <td> elements, - it generates CSS class attributes for each element. You can then add customized CSS rules, even + it generates data attributes for each element. You can then add customized CSS rules, even overriding the Tapestry defaults, to present the Grid as desired. This is often used to set the width of a column to a fixed value. </p> <dl> <dt> - <em>propertyId</em> + data-grid-property="<em>property</em>" </dt> <dd>Added to <th> elements to allow customization of a particular column's header, and added to <td> elements to allow customization of a particular column's data cells. </dd> - <dt>t-first</dt> - <dd>Added to the first <th> and the first <tr> of the <tbody> (the data portion of + <dt>data-grid-column="first"</dt> + <dd>Added to the first <th>. + </dd> + + <dt>data-grid-row="first"</dt> + <dd>Added to the first <tr> of the <tbody> (the data portion of the table). </dd> - <dt>t-last</dt> - <dd>Added to the last <th> and the last <tr>.</dd> + <dt>data-grid-column="last"</dt> + <dd>Added to the last <th>.</dd> + + <dt>data-grid-row="last"</dt> + <dd>Added to the last <tr>.</dd> - <dt>t-sort-column-ascending</dt> + <dt>data-grid-column-sort="ascending"</dt> <dd>Added to the <th> and all corresponding <td> elements for the column that is the current sort column (if any, for ascending sort). </dd> - <dt>t-sort-column-descending</dt> - <dd>As with t-soft-column-ascending, but for a descending sort.</dd> + <dt>data-grid-column-sort="descending"</dt> + <dd>Identifies cells of the sort column for descending..</dd> </dl> <p> - The added CSS classes can get quite verbose; the Grid's lean parameter allows the propertyId CSS - class attribute value to be omitted. Even in lean mode, the other - CSS class attribute values are rendered. + The added attributes can get quite verbose; the Grid's lean parameter allows the data-grid-property attribute + to be omitted. Even in lean mode, the other + attribute values are rendered. </p> </subsection> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/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 c53df86..71fb937 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 @@ -1,4 +1,4 @@ -// Copyright 2007, 2008, 2009, 2011, 2012 The Apache Software Foundation +// Copyright 2007-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. @@ -18,14 +18,11 @@ import org.apache.tapestry5.*; import org.apache.tapestry5.annotations.*; import org.apache.tapestry5.beaneditor.PropertyModel; import org.apache.tapestry5.grid.ColumnSort; -import org.apache.tapestry5.grid.GridConstants; import org.apache.tapestry5.grid.GridModel; import org.apache.tapestry5.grid.GridSortModel; import org.apache.tapestry5.internal.InternalConstants; -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; @@ -70,9 +67,8 @@ public class GridColumns // Use the CSS, Luke! @SuppressWarnings("unused") @Component( - parameters = {"event=sort", "disabled=sortDisabled", "context=columnModel.id", "class=sortLinkClass", - "zone=inherit:zone"}) - private EventLink sort, sort2; + parameters = {"event=sort", "disabled=sortDisabled", "context=columnModel.id", "zone=inherit:zone"}) + private EventLink sort; @Inject @Path("${" + ComponentParameterConstants.GRIDCOLUMNS_ASCENDING_ASSET + "}") @@ -123,21 +119,6 @@ public class GridColumns return !columnModel.isSortable(); } - public String getSortLinkClass() - { - switch (getSortForColumn()) - { - case ASCENDING: - return GridConstants.SORT_ASCENDING_CLASS; - - case DESCENDING: - return GridConstants.SORT_DESCENDING_CLASS; - - default: - return null; - } - } - private ColumnSort getSortForColumn() { GridSortModel sortModel = gridModel.getSortModel(); @@ -147,21 +128,30 @@ public class GridColumns return sortModel.getColumnSort(columnId); } - public String getHeaderClass() - { - List<String> classes = CollectionFactory.newList(); - - if (!lean) classes.add(columnModel.getId()); + void onBeginRenderFromLoop(MarkupWriter writer) { - String sort = getSortLinkClass(); + if (!lean) { + writer.attributes("data-grid-property", columnModel.getId()); + } - if (sort != null) classes.add(sort); + switch (getSortForColumn()) + { + case ASCENDING: + writer.attributes("data-grid-column-sort", "ascending"); + break; - if (index == 0) classes.add(GridConstants.FIRST_CLASS); + case DESCENDING: + writer.attributes("data-grid-column-sort", "descending"); + default: + } - if (index == lastColumnIndex) classes.add(GridConstants.LAST_CLASS); + if (index == 0) { + writer.attributes("data-grid-column", "first"); + } - return TapestryInternalUtils.toClassAttributeValue(classes); + if (index == lastColumnIndex) { + writer.attributes("data-grid-column", "last"); + } } public boolean isActiveSortColumn() http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java index 606e241..f7d83a5 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/GridRows.java @@ -1,4 +1,4 @@ -// Copyright 2007, 2008, 2009, 2011 The Apache Software Foundation +// Copyright 2007-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. @@ -28,17 +28,15 @@ package org.apache.tapestry5.corelib.components; import org.apache.tapestry5.ComponentAction; +import org.apache.tapestry5.MarkupWriter; import org.apache.tapestry5.PropertyOverrides; import org.apache.tapestry5.ValueEncoder; import org.apache.tapestry5.annotations.Environmental; import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.annotations.Property; import org.apache.tapestry5.beaneditor.PropertyModel; -import org.apache.tapestry5.grid.GridConstants; import org.apache.tapestry5.grid.GridDataSource; import org.apache.tapestry5.grid.GridModel; -import org.apache.tapestry5.internal.TapestryInternalUtils; -import org.apache.tapestry5.ioc.internal.util.CollectionFactory; import org.apache.tapestry5.services.FormSupport; import java.util.List; @@ -57,10 +55,10 @@ import java.util.List; * 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 */ -@SuppressWarnings({ "unchecked" }) +@SuppressWarnings({"unchecked"}) public class GridRows { private int startRow; @@ -221,49 +219,51 @@ public class GridRows @Property(write = false) private PropertyModel columnModel; - public String getRowClass() + void onBeginRenderFromRow(MarkupWriter writer) { - List<String> classes = CollectionFactory.newList(); - // Not a cached parameter, so careful to only access it once. - - String rc = rowClass; + if (dataRowIndex == startRow) + { + writer.attributes("data-grid-row", "first"); + } - if (rc != null) classes.add(rc); + if (dataRowIndex == endRow) + { + writer.attributes("data-grid-row", "last"); + } - if (dataRowIndex == startRow) classes.add(GridConstants.FIRST_CLASS); + // Not a cached parameter, so careful to only access it once. - if (dataRowIndex == endRow) classes.add(GridConstants.LAST_CLASS); + String rc = rowClass; - return TapestryInternalUtils.toClassAttributeValue(classes); + if (rc != null) + { + writer.attributes("class", rc); + } } - public String getCellClass() + void onBeginRenderFromColumn(MarkupWriter writer) { - List<String> classes = CollectionFactory.newList(); String id = gridModel.getDataModel().get(propertyName).getId(); if (!lean) { - classes.add(id); + writer.attributes("data-grid-property", id); + } - switch (gridModel.getSortModel().getColumnSort(id)) - { - case ASCENDING: - classes.add(GridConstants.SORT_ASCENDING_CLASS); - break; + switch (gridModel.getSortModel().getColumnSort(id)) + { + case ASCENDING: + writer.attributes("data-grid-column-sort", "ascending"); + break; - case DESCENDING: - classes.add(GridConstants.SORT_DESCENDING_CLASS); - break; + case DESCENDING: + writer.attributes("data-grid-column-sort", "descending"); + break; - default: - } + default: } - - - return TapestryInternalUtils.toClassAttributeValue(classes); } void setupRender() http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/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 74f9bd1..5f79a26 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,16 +1,15 @@ -<thead xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xml:space="default"> - <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"/> - <t:block id="standardHeader"> - <a t:id="sort" rel="nofollow">${columnModel.label}</a> - <t:if test="columnModel.sortable"> - <a t:id="sort2" rel="nofollow"> - <img src="${icon}" class="t-sort-icon" alt="${iconLabel}"/> - </a> +<thead xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xml:space="default"> +<tr data-inplace-grid-links="${inplaceGridLinks}"> + <th t:id="loop" t:type="Loop" source="columnNames" value="columnName" formstate="none" + index="index" t:mixins="rendernotification"> + <t:delegate to="blockForColumn"/> + <t:block id="standardHeader"> + <a t:id="sort" rel="nofollow">${columnModel.label} + <t:if test="! sortDisabled"> + <img src="${icon}" class="pull-right" title="${iconLabel}"/> </t:if> - </t:block> - </th> - </tr> + </a> + </t:block> + </th> +</tr> </thead> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml index f4ece15..b5486e2 100644 --- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml +++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml @@ -1,6 +1,7 @@ -<tr class="${rowClass}" xml:space="default" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> +<tr t:id="row" t:type="any" t:mixins="renderNotification" + xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> <t:loop source="propertyNames" value="propertyName" index="columnIndex" formstate="none"> - <td class="${cellClass}" t:type="any" t:mixins="NotEmpty"> + <td t:id="column" t:type="any" t:mixins="NotEmpty,renderNotification"> <t:gridcell model="columnModel" object="row" overrides="overrides"/> </td> </t:loop> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/test/app1/GridDemo.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/app1/GridDemo.tml b/tapestry-core/src/test/app1/GridDemo.tml index 5fec5da..5a4f12e 100644 --- a/tapestry-core/src/test/app1/GridDemo.tml +++ b/tapestry-core/src/test/app1/GridDemo.tml @@ -11,8 +11,8 @@ </t:parameter> </table> - <p> - [<t:actionlink t:id="reset">reset the Grid</t:actionlink>] - </p> + <div> + <t:actionlink t:id="reset" class="btn">Reset the Grid</t:actionlink> + </div> </html> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/GridSymbolDemoTests.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/GridSymbolDemoTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/GridSymbolDemoTests.groovy index 1b98dc2..c351e46 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/GridSymbolDemoTests.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/GridSymbolDemoTests.groovy @@ -1,4 +1,4 @@ -// Copyright 2011 The Apache Software Foundation +// Copyright 2011-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. @@ -29,10 +29,9 @@ class GridSymbolDemoTests extends TapestryCoreTestCase clickAndWait "link=4" - // Using the XPath selectors was a bit flakey, so maybe css is better. - assertText("css=tr.t-first td.me", "6"); - assertText("css=tr.t-first td.odd", "false"); - assertText("css=tr.t-last td.me", "7"); - assertText("css=tr.t-first td.odd", "false"); + assertText("css=tr[data-grid-row=first] td[data-grid-property=me]", "6"); + assertText("css=tr[data-grid-row=first] td[data-grid-property=odd]", "false"); + assertText("css=tr[data-grid-row=last] td[data-grid-property=me]", "7"); + assertText("css=tr[data-grid-row=last] td[data-grid-property=odd]", "true"); } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/components/Layout.groovy ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/components/Layout.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/components/Layout.groovy index b3c6096..132b69a 100644 --- a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/components/Layout.groovy +++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/symbolparam/components/Layout.groovy @@ -1,4 +1,4 @@ -// Copyright 2011 The Apache Software Foundation +// Copyright 2011-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. @@ -14,11 +14,13 @@ package org.apache.tapestry5.integration.symbolparam.components +import org.apache.tapestry5.annotations.Import import org.apache.tapestry5.annotations.Property import org.apache.tapestry5.ioc.annotations.Inject import org.apache.tapestry5.services.Request import org.apache.tapestry5.services.Session +@Import(stack="core") class Layout { @Inject http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/dc342eb1/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java index a35944f..d5c70d5 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java @@ -1,4 +1,4 @@ -// Copyright 2009, 2011 The Apache Software Foundation +// Copyright 2009-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. @@ -23,13 +23,16 @@ import org.testng.annotations.Test; */ public class GridTests extends TapestryCoreTestCase { + + private static final String RESET = "Reset the Grid"; + /** * Basic Grid rendering, with a column render override. Also tests sorting. */ @Test public void basic_grid() { - openLinks("Grid Demo", "reset the Grid"); + openLinks("Grid Demo", RESET); // "Sort Rating" via the header cell override (TAPESTRY-2081) @@ -77,9 +80,9 @@ public class GridTests extends TapestryCoreTestCase clickAndWait("link=Title"); - assertAttributeValueEndsWith("//img[@class='t-sort-icon']/@src", "/sort-asc.png"); + assertAttributeValueEndsWith("//th/a/img/@src", "/sort-asc.png"); - assertAttribute("//img[@class='t-sort-icon']/@alt", "[Asc]"); + assertAttribute("//th/a/img/@title", "[Asc]"); clickAndWait("link=1"); @@ -87,10 +90,10 @@ public class GridTests extends TapestryCoreTestCase clickAndWait("link=Title"); - assertAttributeValueEndsWith("//img[@class='t-sort-icon']/@src", "/sort-desc.png"); - assertAttribute("//img[@class='t-sort-icon']/@alt", "[Desc]"); + assertAttributeValueEndsWith("//th/a/img/@src", "/sort-desc.png"); + assertAttribute("//th/a/img/@title", "[Desc]"); - clickAndWait("link=reset the Grid"); + clickAndWait("link=" + RESET); // Back to where we started. @@ -317,7 +320,7 @@ public class GridTests extends TapestryCoreTestCase @Test public void rel_nofollow_present_in_sort_links() { - openLinks("Grid Demo", "reset the Grid"); + openLinks("Grid Demo", RESET); assertAttribute("//a[contains(@href,'columns:sort')]/@rel", "nofollow"); }
