You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2014/01/10 19:43:57 UTC
git commit: TAP5-244
Updated Branches:
refs/heads/master 3819b855d -> 66a0a9bd5
TAP5-244
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/66a0a9bd
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/66a0a9bd
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/66a0a9bd
Branch: refs/heads/master
Commit: 66a0a9bd5674173cbc6aef831ecedbf33eca8a5b
Parents: 3819b855
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Fri Jan 10 16:43:28 2014 -0200
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Fri Jan 10 16:43:28 2014 -0200
----------------------------------------------------------------------
.../TapestryBeanValidationIntegrationTests.java | 2 -
.../tapestry5/corelib/components/Grid.java | 23 +++++-
.../tapestry5/corelib/components/Grid.tml | 11 ++-
tapestry-core/src/test/app1/EmptyGrid.tml | 19 +++++
.../tapestry5/integration/app1/GridTests.java | 21 +++++
.../integration/app1/pages/EmptyGrid.java | 83 ++++++++++++++++++++
.../tapestry5/integration/app1/pages/Index.java | 2 +
7 files changed, 153 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java b/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
index ef97a54..6960913 100644
--- a/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
+++ b/tapestry-beanvalidator/src/test/java/org/apache/tapestry5/beanvalidator/integration/TapestryBeanValidationIntegrationTests.java
@@ -272,6 +272,4 @@ public class TapestryBeanValidationIntegrationTests extends SeleniumTestCase
}
-
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/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 cde54c7..2a37214 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, 2012 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010, 2011, 2012, 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.
@@ -193,6 +193,15 @@ public class Grid implements GridModel, ClientElement
*/
@Parameter
private boolean inPlace;
+
+ /**
+ * If true, then the Grid will also render a table element complete with headers if the data source is empty.
+ * If set to true, a model parameter will have to be specified. A default model for a specific class can be
+ * created using {@link BeanModelSource#createDisplayModel(Class, org.apache.tapestry5.ioc.Messages)}.
+ */
+ @Parameter
+ private boolean renderTableIfEmpty = false;
+
/**
* The name of the pseudo-zone that encloses the Grid. Starting in 5.4, this is always either
@@ -377,6 +386,7 @@ public class Grid implements GridModel, ClientElement
*/
protected Binding defaultModel()
{
+
return new AbstractBinding()
{
public Object get()
@@ -387,7 +397,7 @@ public class Grid implements GridModel, ClientElement
Class rowType = gridDataSource.getRowType();
- if (rowType == null)
+ if (renderTableIfEmpty || rowType == null)
throw new RuntimeException(
String.format(
"Unable to determine the bean type for rows from %s. You should bind the model parameter explicitly.",
@@ -437,7 +447,7 @@ public class Grid implements GridModel, ClientElement
// If there's no rows, display the empty block placeholder.
- return cachingSource.getAvailableRows() == 0 ? empty : null;
+ return !renderTableIfEmpty && cachingSource.getAvailableRows() == 0 ? empty : null;
}
void setupDataSource()
@@ -478,7 +488,7 @@ public class Grid implements GridModel, ClientElement
// The empty placeholder will already have rendered.
if (cachingSource.getAvailableRows() == 0)
- return false;
+ return !renderTableIfEmpty ? false : null;
if (inPlace && zone == null)
{
@@ -517,6 +527,11 @@ public class Grid implements GridModel, ClientElement
return dataModel;
}
+
+ public int getNumberOfProperties()
+ {
+ return getDataModel().getPropertyNames().size();
+ }
public GridDataSource getDataSource()
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/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 e4513ee..0e5979c 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,11 +1,18 @@
-<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
+<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xmlns:p="tapestry:parameter">
<div t:id="pagerTop"/>
<table t:id="table">
<thead t:id="columns"/>
<tbody>
- <tr t:id="rows"/>
+ <t:if test="dataSource.availableRows">
+ <tr t:id="rows"/>
+ </t:if>
+ <t:if test="!dataSource.availableRows">
+ <tr>
+ <td colspan="${numberOfProperties}"><t:delegate to="block:empty"/></td>
+ </tr>
+ </t:if>
</tbody>
</table>
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/tapestry-core/src/test/app1/EmptyGrid.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/EmptyGrid.tml b/tapestry-core/src/test/app1/EmptyGrid.tml
new file mode 100644
index 0000000..9d0853f
--- /dev/null
+++ b/tapestry-core/src/test/app1/EmptyGrid.tml
@@ -0,0 +1,19 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
+
+ <h1>Empty Grid Demo</h1>
+
+ <p>A grid with an empty data source.</p>
+
+ <t:if test="removeExplicitModel">
+ <table t:type="Grid" source="source" renderTableIfEmpty="true"/>
+ </t:if>
+ <t:if test="!removeExplicitModel">
+ <table t:type="Grid" source="source" renderTableIfEmpty="true" model="model"/>
+ </t:if>
+
+
+ <div>
+ <t:eventlink event="removemodel" class="btn">Remove the Grid's model</t:eventlink>
+ </div>
+
+</html>
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/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 59b4768..37407e5 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
@@ -143,6 +143,27 @@ public class GridTests extends App1TestCase
assertTextPresent("There is no data to display.");
}
+
+
+ // TAP5-244
+ @Test
+ public void empty_grid_with_columns() throws Exception
+ {
+ openLinks("Empty Grid Demo");
+
+ assertText("//th[1]", "Random");
+
+ assertText("//table/tbody/tr/td[@colspan='1']", "There is no data to display.");
+ }
+
+ // TAP5-244
+ @Test
+ public void empty_grid_with_columns_requires_model_parameter() throws Exception
+ {
+ openLinks("Empty Grid Demo", "Remove the Grid's model");
+
+ assertTextPresent("You should bind the model parameter explicitly.");
+ }
@Test
public void grid_inside_form()
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/EmptyGrid.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/EmptyGrid.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/EmptyGrid.java
new file mode 100644
index 0000000..522fa6a
--- /dev/null
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/EmptyGrid.java
@@ -0,0 +1,83 @@
+// 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 java.lang.annotation.Annotation;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+import org.apache.tapestry5.PropertyConduit;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.beaneditor.BeanModel;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.BeanModelSource;
+
+public class EmptyGrid
+{
+
+ @Property
+ @Persist
+ private boolean removeExplicitModel;
+
+ @Inject
+ private BeanModelSource beanModelSource;
+
+ @Inject
+ private Messages messages;
+
+ private Random random = new Random();
+
+ public List getSource()
+ {
+ return Collections.emptyList();
+ }
+
+ public BeanModel getModel()
+ {
+ BeanModel<Object> model = beanModelSource.createDisplayModel(Object.class, messages);
+ model.add("random", new PropertyConduit() {
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
+ {
+ return null;
+ }
+
+ public void set(Object instance, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class getPropertyType()
+ {
+ return Long.class;
+ }
+
+ public Object get(Object instance)
+ {
+ return random.nextLong();
+ }
+ });
+ return model;
+ }
+
+ void onRemoveModel()
+ {
+ removeExplicitModel = true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/66a0a9bd/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 3d276ca..96b7bd9 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
@@ -318,6 +318,8 @@ public class Index
new Item("GridRemoveReorderDemo", "Grid Remove/Reorder Demo",
"handling of remove and reorder parameters"),
+
+ new Item("EmptyGrid", "Empty Grid Demo", "show table for empty data sources"),
new Item("protected", "Protected Page",
"Demonstrate result of non-void return from a page's activate method"),