You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2011/04/18 19:11:48 UTC
svn commit: r1094660 - in /wicket/trunk/wicket-extensions/src:
main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/
test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/
Author: mgrigorov
Date: Mon Apr 18 17:11:48 2011
New Revision: 1094660
URL: http://svn.apache.org/viewvc?rev=1094660&view=rev
Log:
WICKET-3603 DataTable row groups are present in markup even when they contain no rows.
Show thead and tfoot only if there is something to show in them.
Modified:
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.html
wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java
wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTablePage_ExpectedResult.html
wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTableTest.java
Modified: wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.html?rev=1094660&r1=1094659&r2=1094660&view=diff
==============================================================================
--- wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.html (original)
+++ wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.html Mon Apr 18 17:11:48 2011
@@ -17,11 +17,11 @@
-->
<wicket:panel>
-<thead>
- <wicket:container wicket:id="topToolbars"></wicket:container>
+<thead wicket:id="topToolbars">
+ <wicket:container wicket:id="toolbars"></wicket:container>
</thead>
-<tfoot>
- <wicket:container wicket:id="bottomToolbars"></wicket:container>
+<tfoot wicket:id="bottomToolbars">
+ <wicket:container wicket:id="toolbars"></wicket:container>
</tfoot>
<tbody wicket:id="body">
<tr wicket:id="rows">
Modified: wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java?rev=1094660&r1=1094659&r2=1094660&view=diff
==============================================================================
--- wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java (original)
+++ wicket/trunk/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.java Mon Apr 18 17:11:48 2011
@@ -33,6 +33,8 @@ import org.apache.wicket.markup.repeater
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
/**
@@ -109,9 +111,9 @@ public class DataTable<T> extends Panel
private final List<IColumn<T>> columns;
- private final RepeatingView topToolbars;
+ private final ToolbarsContainer topToolbars;
- private final RepeatingView bottomToolbars;
+ private final ToolbarsContainer bottomToolbars;
/**
* Constructor
@@ -320,14 +322,14 @@ public class DataTable<T> extends Panel
return datagrid.getItemCount();
}
- private void addToolbar(final AbstractToolbar toolbar, final RepeatingView container)
+ private void addToolbar(final AbstractToolbar toolbar, final ToolbarsContainer container)
{
if (toolbar == null)
{
throw new IllegalArgumentException("argument [toolbar] cannot be null");
}
- container.add(toolbar);
+ container.getRepeatingView().add(toolbar);
}
/**
@@ -392,14 +394,18 @@ public class DataTable<T> extends Panel
}
/**
- * This class acts as a repeater that will contain the toolbar.
+ * This class acts as a repeater that will contain the toolbar. It makes sure that the table row
+ * group (e.g. thead) tags are only visible when they contain rows in accordance with the HTML
+ * specification.
*
* @author igor.vaynberg
*/
- private static class ToolbarsContainer extends RepeatingView
+ private static class ToolbarsContainer extends WebMarkupContainer
{
private static final long serialVersionUID = 1L;
+ private final RepeatingView toolbars;
+
/**
* Constructor
*
@@ -408,6 +414,41 @@ public class DataTable<T> extends Panel
private ToolbarsContainer(final String id)
{
super(id);
+ toolbars = new RepeatingView("toolbars");
+ add(toolbars);
+ }
+
+ public RepeatingView getRepeatingView()
+ {
+ return toolbars;
+ }
+
+ @Override
+ public boolean isVisible()
+ {
+ if (!super.isVisible())
+ {
+ return false;
+ }
+
+ toolbars.configure();
+
+ Boolean visible = toolbars.visitChildren(new IVisitor<Component, Boolean>()
+ {
+ public void component(Component object, IVisit<Boolean> visit)
+ {
+ object.configure();
+ if (object.isVisible())
+ {
+ visit.stop(Boolean.TRUE);
+ }
+ else
+ {
+ visit.dontGoDeeper();
+ }
+ }
+ });
+ return visible == Boolean.TRUE;
}
}
}
Modified: wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTablePage_ExpectedResult.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTablePage_ExpectedResult.html?rev=1094660&r1=1094659&r2=1094660&view=diff
==============================================================================
--- wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTablePage_ExpectedResult.html (original)
+++ wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTablePage_ExpectedResult.html Mon Apr 18 17:11:48 2011
@@ -1,75 +1,74 @@
-<html xmlns:wicket>
-<body>
- <table class="dataview" cellspacing="0" wicket:id="table"><wicket:panel>
-<thead>
- <wicket:container wicket:id="topToolbars"><wicket:panel>
- <tr class="navigation">
- <td wicket:id="span" colspan="6">
- <x/>
- <x/></td><x/></tr><x/></wicket:panel></wicket:container><wicket:container wicket:id="topToolbars"><wicket:panel>
- <tr class="headers">
- <th wicket:id="header"><x/></th>
- <th wicket:id="header" class="numeric"><x/></th>
- <th wicket:id="header" class="wicket_orderUp"><wicket:border><x/></wicket:border></th>
- <th wicket:id="header" class="wicket_orderNone last-name"><wicket:border><x/></wicket:border></th>
- <th wicket:id="header"><x/></th>
- <th wicket:id="header"><x/></th><x/></tr><x/></wicket:panel></wicket:container><x/></thead>
-<tfoot><x/></tfoot>
-<tbody wicket:id="body">
- <tr wicket:id="rows" class="even">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="odd">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="even">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="odd">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="even">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="odd">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="even">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><tr wicket:id="rows" class="odd">
- <td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="numeric">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells" class="last-name">
- <x/></td><td wicket:id="cells">
- <x/></td><td wicket:id="cells">
- <x/></td><x/></tr><x/></tbody><x/></wicket:panel></table><x/></body><x/></html>
+<html xmlns:wicket>
+<body>
+ <table class="dataview" cellspacing="0" wicket:id="table"><wicket:panel>
+<thead wicket:id="topToolbars">
+ <wicket:container wicket:id="toolbars"><wicket:panel>
+ <tr class="navigation">
+ <td wicket:id="span" colspan="6">
+ <x/>
+ <x/></td><x/></tr><x/></wicket:panel></wicket:container><wicket:container wicket:id="toolbars"><wicket:panel>
+ <tr class="headers">
+ <th wicket:id="header"><x/></th>
+ <th wicket:id="header" class="numeric"><x/></th>
+ <th wicket:id="header" class="wicket_orderUp"><wicket:border><x/></wicket:border></th>
+ <th wicket:id="header" class="wicket_orderNone last-name"><wicket:border><x/></wicket:border></th>
+ <th wicket:id="header"><x/></th>
+ <th wicket:id="header"><x/></th><x/></tr><x/></wicket:panel></wicket:container><x/></thead>
+<tbody wicket:id="body">
+ <tr wicket:id="rows" class="even">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="odd">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="even">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="odd">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="even">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="odd">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="even">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><tr wicket:id="rows" class="odd">
+ <td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="numeric">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells" class="last-name">
+ <x/></td><td wicket:id="cells">
+ <x/></td><td wicket:id="cells">
+ <x/></td><x/></tr><x/></tbody><x/></wicket:panel></table><x/></body><x/></html>
Modified: wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTableTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTableTest.java?rev=1094660&r1=1094659&r2=1094660&view=diff
==============================================================================
--- wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTableTest.java (original)
+++ wicket/trunk/wicket-extensions/src/test/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTableTest.java Mon Apr 18 17:11:48 2011
@@ -16,10 +16,27 @@
*/
package org.apache.wicket.extensions.markup.html.repeater.data.table;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
import junit.framework.TestCase;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.repeater.data.IDataProvider;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.util.tester.DiffUtil;
import org.apache.wicket.util.tester.WicketTester;
+import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,6 +45,9 @@ import org.slf4j.LoggerFactory;
*/
public class DataTableTest extends TestCase
{
+ /** Log for reporting. */
+ private static final Logger log = LoggerFactory.getLogger(DataTableTest.class);
+
private WicketTester tester;
@Override
@@ -42,9 +62,6 @@ public class DataTableTest extends TestC
tester.destroy();
}
- /** Log for reporting. */
- private static final Logger log = LoggerFactory.getLogger(DataTableTest.class);
-
/**
* @throws Exception
*/
@@ -73,6 +90,26 @@ public class DataTableTest extends TestC
DiffUtil.validatePage(doc, getClass(), "DataTablePage_ExpectedResult.html", true);
}
+ /**
+ * Tests that DataTable doesn't produce thead/tfoot if there are no top/bottom toolbars or if
+ * their children components are all invisible
+ */
+ public void testWicket3603()
+ {
+ PageParameters parameters = new PageParameters();
+ parameters.add("empty", Boolean.TRUE);
+ tester.startPage(Wicket3603Page.class, parameters);
+ System.err.println(tester.getLastResponseAsString());
+ Assert.assertTrue(tester.getLastResponseAsString().contains("thead"));
+ Assert.assertTrue(tester.getLastResponseAsString().contains("tfoot"));
+
+ parameters.set("empty", Boolean.FALSE);
+ tester.startPage(Wicket3603Page.class);
+ System.err.println(tester.getLastResponseAsString());
+ Assert.assertFalse(tester.getLastResponseAsString().contains("thead"));
+ Assert.assertFalse(tester.getLastResponseAsString().contains("tfoot"));
+ }
+
private String removeFillers(String doc)
{
doc = doc.replaceAll("(?s)<span .*?>.*?</span>", "<x/>");
@@ -84,4 +121,67 @@ public class DataTableTest extends TestC
return doc;
}
+
+ /**
+ * A page with a DataTable that either has items (tbody) or header and footer (thead/tfoot)
+ */
+ public static class Wicket3603Page extends WebPage implements IMarkupResourceStreamProvider
+ {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct.
+ *
+ * @param parameters
+ */
+ public Wicket3603Page(PageParameters parameters)
+ {
+ super(parameters);
+
+ IDataProvider<Number> provider = new IDataProvider<Number>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ private List<Integer> items = Arrays.asList(1, 3, 5);
+
+ public void detach()
+ {
+ }
+
+ public Iterator<? extends Number> iterator(int first, int count)
+ {
+ StringValue emptyValue = getPageParameters().get("empty");
+ return emptyValue.toBoolean() ? Collections.<Integer> emptyList().iterator()
+ : items.iterator();
+ }
+
+ public int size()
+ {
+ StringValue emptyValue = getPageParameters().get("empty");
+ return emptyValue.toBoolean() ? 0 : items.size();
+ }
+
+ public IModel<Number> model(Number object)
+ {
+ return Model.of(object);
+ }
+ };
+
+ List<IColumn<Number>> columns = new ArrayList<IColumn<Number>>();
+ columns.add(new PropertyColumn<Number>(Model.of("value"), "value"));
+
+ DataTable<Number> table = new DataTable<Number>("table", columns, provider, 10);
+ table.addBottomToolbar(new NoRecordsToolbar(table));
+ table.addTopToolbar(new NoRecordsToolbar(table));
+ add(table);
+ }
+
+ public IResourceStream getMarkupResourceStream(MarkupContainer container,
+ Class<?> containerClass)
+ {
+ return new StringResourceStream(
+ "<html><body><table wicket:id='table'></table></body></html>");
+ }
+
+ }
}