You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by bc...@apache.org on 2010/06/29 21:02:20 UTC
svn commit: r959073 - in /click/trunk/click/framework:
src/org/apache/click/control/Column.java
src/org/apache/click/control/Table.java
test/org/apache/click/control/TableTest.java
Author: bckfnn
Date: Tue Jun 29 19:02:20 2010
New Revision: 959073
URL: http://svn.apache.org/viewvc?rev=959073&view=rev
Log:
add support for table <caption> and for headers attribute on <td>. CLK-673
Modified:
click/trunk/click/framework/src/org/apache/click/control/Column.java
click/trunk/click/framework/src/org/apache/click/control/Table.java
click/trunk/click/framework/test/org/apache/click/control/TableTest.java
Modified: click/trunk/click/framework/src/org/apache/click/control/Column.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Column.java?rev=959073&r1=959072&r2=959073&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Column.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Column.java Tue Jun 29 19:02:20 2010
@@ -1171,6 +1171,7 @@ public class Column implements Serializa
buffer.elementStart("td");
if (getRenderId()) {
buffer.appendAttribute("id", getId() + "_" + rowIndex);
+ buffer.appendAttribute("headers", getId());
}
buffer.appendAttribute("class", getDataClass());
@@ -1227,6 +1228,9 @@ public class Column implements Serializa
if (hasAttributes()) {
buffer.appendAttributes(getAttributes());
}
+ if (getRenderId()) {
+ buffer.appendAttribute("id", getId());
+ }
buffer.closeTag();
Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Table.java?rev=959073&r1=959072&r2=959073&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Table.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Table.java Tue Jun 29 19:02:20 2010
@@ -386,6 +386,9 @@ public class Table extends AbstractContr
*/
protected int bannerPosition = POSITION_BOTTOM;
+ /** The table HTML <caption> element */
+ protected String caption;
+
/** The map of table columns keyed by column name. */
protected Map<String, Column> columns = new HashMap<String, Column>();
@@ -564,6 +567,22 @@ public class Table extends AbstractContr
}
/**
+ * Return the content of the HTML table's <tt><caption></tt> elements.
+ * @return the tables caption or <tt>null</tt> if not defined.
+ */
+ public String getCaption() {
+ return caption;
+ }
+
+ /**
+ * Set the HTML table's <tt><caption></tt> element.
+ * @param caption the content of the caption element.
+ */
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ /**
* Set the HTML class attribute.
* <p/>
* <b>Note:</b> this method will replace the existing <tt>"class"</tt>
@@ -1502,7 +1521,15 @@ public class Table extends AbstractContr
buffer.closeTag();
buffer.append("\n");
-
+
+ String caption = getCaption();
+ if (caption != null) {
+ buffer.elementStart("caption");
+ buffer.closeTag();
+ buffer.append(caption);
+ buffer.elementEnd("caption");
+ buffer.append("\n");
+ }
// Render table header
renderHeaderRow(buffer);
Modified: click/trunk/click/framework/test/org/apache/click/control/TableTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/TableTest.java?rev=959073&r1=959072&r2=959073&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/TableTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/TableTest.java Tue Jun 29 19:02:20 2010
@@ -64,9 +64,9 @@ public class TableTest extends TestCase
column.setSortable(false);
table.addColumn(column);
- String header = "<thead>\n<tr>\n<th>Name</th></tr></thead>\n";
- String row1 = "<tr class=\"odd\">\n<td id=\"Foos-Name_0\">foo1</td></tr>\n";
- String row2 = "<tr class=\"even\">\n<td id=\"Foos-Name_1\">foo2</td></tr>";
+ String header = "<thead>\n<tr>\n<th id=\"Foos-Name\">Name</th></tr></thead>\n";
+ String row1 = "<tr class=\"odd\">\n<td id=\"Foos-Name_0\" headers=\"Foos-Name\">foo1</td></tr>\n";
+ String row2 = "<tr class=\"even\">\n<td id=\"Foos-Name_1\" headers=\"Foos-Name\">foo2</td></tr>";
String body = "<tbody>\n" + row1 + row2 + "</tbody>";
assertEquals("<table id=\"Foos\">\n" + header + body + "</table>\n", table.toString());
}
@@ -112,6 +112,7 @@ public class TableTest extends TestCase
}
Table table = new Table("table") {
+ @Override
protected void addRowAttributes(Map attributes, Object row, int rowIndex) {
Foo foo = (Foo) row;
attributes.put("id", foo.getName());
@@ -143,5 +144,45 @@ public class TableTest extends TestCase
return name;
}
}
+
+ /**
+ * Test CLK-673 headers attribute
+ */
+ public void testHeaders() {
+ MockContext.initContext();
+ List<Foo> foos = new ArrayList<Foo>();
+ foos.add(new Foo("foo1"));
+ foos.add(new Foo("foo2"));
+
+ Table table = new Table("table");
+ table.setRenderId(true);
+ table.setRowList(foos);
+ Column column = new Column("name");
+ table.addColumn(column);
+
+ System.out.println(table.toString());
+ assertTrue(table.toString().contains("<th id=\"table-name\">"));
+ assertTrue(table.toString().contains("<td id=\"table-name_1\" headers=\"table-name\">"));
+ }
+
+
+ /**
+ * Test CLK-673 caption
+ */
+ public void testCaption() {
+ MockContext.initContext();
+
+ List<Foo> foos = new ArrayList<Foo>();
+ foos.add(new Foo("foo1"));
+ foos.add(new Foo("foo2"));
+
+ Table table = new Table("table");
+ table.setCaption("caption<tt>tt</tt>");
+ table.setRowList(foos);
+ Column column = new Column("name");
+ table.addColumn(column);
+
+ assertTrue(table.toString().contains("<caption>caption<tt>tt</tt></caption>"));
+ }
}