org.apache.click.control
Class Table

java.lang.Object
  extended by org.apache.click.control.AbstractControl
      extended by org.apache.click.control.Table
All Implemented Interfaces:
Serializable, Control, Stateful

public class Table
extends AbstractControl
implements Stateful

Provides a HTML Table control: <table>.

The Table control provides a HTML <table> control with DisplayTag like functionality. The design of the Table control has been informed by the excellent DisplayTag library.

Table Example

An example Table usage is provided below:
 public class CustomersPage extends BorderPage {

     public Table table = new Table();
     public ActionLink deleteLink = new ActionLink("Delete", this, "onDeleteClick");

     public CustomersPage() {
         table.setClass(Table.CLASS_ITS);
         table.setPageSize(4);
         table.setShowBanner(true);
         table.setSortable(true);

         table.addColumn(new Column("id"));
         table.addColumn(new Column("name"));

         Column column = new Column("email");
         column.setAutolink(true);
         table.addColumn(column);

         table.addColumn(new Column("investments"));

         column = new Column("Action");
         column.setDecorator(new LinkDecorator(table, deleteLink, "id"));
         column.setSortable(false);
         table.addColumn(column);

         // Set data provider to populate the table row list from
         table.setDataProvider(new DataProvider() {
             public List getData() {
                 return getCustomerService().getCustomersSortedByName();
             }
         });
     }

     public boolean onDeleteClick() {
         Integer id = deleteLink.getValueInteger();
         getCustomerService().deleteCustomer(id);
         return true;
     }
 } 

DataProvider

In the example above a DataProvider is used to populate the Table row list from. DataProviders are used to provide data on demand to controls. For very large data sets use a PagingDataProvider instead. See the section large data sets for details.

CSS and JavaScript resources

The Table control makes use of the following resources (which Click automatically deploys to the application directory, /click): To import the Table CSS styles and any control JavaScript simply reference the variables $headElements and $jsElements in the page template. For example:
 <html>
 <head>
 $headElements
 </head>
 <body>

 $table

 $jsElements
 </body>
 </html> 

Table Styles

The table CSS style sheet is adapted from the DisplayTag screen.css style sheet and includes the styles: To use one of these CSS styles set the table "class" attribute. For example in a page constructor:
 public LineItemsPage() {
     Table table = new Table("table");
     table.setClass(Table.CLASS_SIMPLE);
     ..
 } 
An alternative method of specifying the table class to use globally for your application is to define a table-default-class message property in your applications click-pages.properties file. For example:
 table-default-class=blue2 

Paging

Table provides out-of-the-box paging.

To enable Paging set the table's page size: setPageSize(int) and optionally make the Table Banner visible: setShowBanner(boolean).

Table supports rendering different paginators through the method setPaginator. The default Table Paginator is TablePaginator.

Sorting

Table also has built in column sorting.

To enable/disable sorting use setSortable(boolean).

Custom Parameters - preserve state when paging and sorting

Its often necessary to add extra parameters on the Table links in order to preserve state when navigating between pages or sorting columns.

One can easily add extra parameters to links generated by the Table through the Table's controlLink.

For example:

 public CompanyPage extends BorderPage {

      // companyId is the criteria used to limit Table rows to clients from
      // the specified company. This variable could be selected from a drop
      // down list or similar means.
      public String companyId;

      public Table table = new Table();

      public onInit() {
          // Set the companyId on the table's controlLink. If you view the
          // output rendered by Table note that the companyId parameter
          // is rendered for each Paging and Sorting link.
          table.getControlLink().setParameter("companyId", companyId);

          // Set data provider to populate the table row list from
          table.setDataProvider(new DataProvider() {
              public List getData() {
                  return getCompanyDao().getCompanyClients(companyId);
              }
          });
      }

      ...
 } 

Row Attributes

Sometimes it is useful to add HTML attributes on individual rows. For these cases one can override the method addRowAttributes(java.util.Map, java.lang.Object, int) and add custom attributes to the row's attribute Map.

Large Datasets

For large data sets use a PagingDataProvider.

A PagingDataProvider has two responsibilities. First, it must load only those rows to be displayed on the current page e.g. rows 50 - 59. Second, it must return the total number of rows represented by the PagingDataProvider.

The Table methods getFirstRow(), getLastRow() and getPageSize() provides the necessary information to limit the rows to the selected page. For sorting, the Table methods getSortedColumn() and isSortedAscending() provides the necessary information to sort the data.

Please note: when using a PagingDataProvider, you are responsible for sorting the data, as the Table does not have access to all the data.

Example usage:

 public CustomerPage() {
     Table table = new Table("table");
     table.setPageSize(10);
     table.setShowBanner(true);
     table.setSortable(true);

     table.addColumn(new Column("id"));
     table.addColumn(new Column("name"));
     table.addColumn(new Column("investments"));

     table.setDataProvider(new PagingDataProvider() {

         public List getData() {
             int start = table.getFirstRow();
             int count = table.getPageSize();
             String sortColumn = table.getSortedColumn();
             boolean ascending = table.isSortedAscending();

             return getCustomerService().getCustomersForPage(start, count, sortColumn, ascending);
         }

         public int size() {
             return getCustomerService().getNumberOfCustomers();
         }
     });
 } 
For a live demonstration see the Large Dataset Demo.

See the W3C HTML reference Tables and the W3C CSS reference Tables.

See Also:
Column, Decorator, Serialized Form

Field Summary
static String ASCENDING
          The control ActionLink page number parameter name: "ascending".
protected  int bannerPosition
          The table pagination banner position: [ POSITION_TOP | POSITION_BOTTOM | POSITION_BOTH ].
protected  String caption
          The table HTML <caption> element.
static String CLASS_BLUE1
          The table CSS style: "blue1".
static String CLASS_BLUE2
          The table CSS style: "blue2".
static String CLASS_COMPLEX
          The table CSS style: "complex".
static String CLASS_ISI
          The table CSS style: "isi".
static String CLASS_ITS
          The table CSS style: "its".
static String CLASS_MARS
          The table CSS style: "mars".
static String CLASS_NOCOL
          The table CSS style: "nocol".
static String CLASS_ORANGE1
          The table CSS style: "orange1".
static String CLASS_ORANGE2
          The table CSS style: "orange2".
static String CLASS_REPORT
          The table CSS style: "report".
static String CLASS_SIMPLE
          The table CSS style: "simple".
static String[] CLASS_STYLES
          The array of pre-defined table CSS class styles.
static String COLUMN
          The control ActionLink sorted column parameter name: "column".
protected  List<Column> columnList
          The list of table Columns.
protected  Map<String,Column> columns
          The map of table columns keyed by column name.
protected  ActionLink controlLink
          The table paging and sorting control action link.
protected  List<Control> controlList
          The list of table controls.
protected  DataProvider dataProvider
          The table data provider.
protected  String height
          The table HTML <td> height attribute.
protected  boolean hoverRows
          The table rows set 'hover' CSS class on mouseover events flag.
protected  boolean nullifyRowListOnDestroy
          Deprecated. stateful pages are not supported anymore, use stateful Controls instead
static String PAGE
          The control ActionLink page number parameter name: "page".
protected  int pageNumber
          The currently displayed page number.
protected  int pageSize
          The maximum page size in rows.
protected  Renderable paginator
          The paginator used to render the table pagination controls.
static int PAGINATOR_ATTACHED
          The attached style pagination banner position.
static int PAGINATOR_DETACHED
          The detached style pagination banner position.
static int PAGINATOR_INLINE
          The attached style pagination banner position.
protected  int paginatorAttachment
          The paginator attachment style: [ PAGINATOR_ATTACHED | PAGINATOR_DETACHED | PAGINATOR_INLINE ].
static int POSITION_BOTH
          The table top and bottom pagination banner position.
static int POSITION_BOTTOM
          The table bottom pagination banner position.
static int POSITION_TOP
          The table top pagination banner position.
protected  boolean renderId
          The default column render id attribute status.
protected  int rowCount
          The total possible number of rows of the table.
protected  List rowList
          The list Table rows.
protected  boolean showBanner
          The show table banner flag detailing number of rows and current rows displayed.
static String SORT
          The control ActionLink sort number parameter name: "sort".
protected  boolean sortable
          The default column are sortable status.
protected  boolean sorted
          The row list is sorted status.
protected  boolean sortedAscending
          The rows list is sorted in ascending order.
protected  String sortedColumn
          The name of the sorted column.
protected  String width
          The table HTML <td> width attribute.
 
Fields inherited from class org.apache.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface org.apache.click.Control
CONTROL_MESSAGES
 
Constructor Summary
Table()
          Create a Table with no name defined.
Table(String name)
          Create an Table for the given name.
 
Method Summary
 Control add(Control control)
          Add the given Control to the table.
 Column addColumn(Column column)
          Add the column to the table.
 Control addControl(Control control)
          Deprecated. use add(org.apache.click.Control) instead
protected  void addRowAttributes(Map<String,String> attributes, Object row, int rowIndex)
          Override this method to set HTML attributes for each Table row.
protected  List<Object> createRowList()
          Create a new table row list.
 int getBannerPosition()
          Return the Table pagination banner position.
 String getCaption()
          Return the content of the table <caption> element, or null if not defined.
 Column getColumn(String name)
          Return the Column for the given name.
 List<Column> getColumnList()
          Return the list of table columns.
 Map<String,Column> getColumns()
          Return the Map of table Columns, keyed on column name.
 ActionLink getControlLink()
          Return the table paging and sorting control action link.
 List<Control> getControls()
          Return the list of Controls added to the table.
 int getControlSizeEst()
          Return the estimated rendered control size in characters.
 DataProvider getDataProvider()
          Return the table row list DataProvider.
 int getFirstRow()
          Return the index of the first row to display.
 List<Element> getHeadElements()
          Return the Table HTML HEAD elements for the following resource: click/table.css Additionally, the HEAD elements of the getControlLink() will also be returned.
 String getHeight()
          Return the table HTML <td> height attribute.
 boolean getHoverRows()
          Return true if the table row (<tr>) elements should have the class="hover" attribute set on JavaScript mouseover events.
 int getLastRow()
          Return the index of the last row to display.
 boolean getNullifyRowListOnDestroy()
          Return true if the Table will nullify the rowList when the onDestroy() method is invoked.
 int getNumberPages()
          Return the number of pages to display.
 int getPageNumber()
          Return the currently displayed page number.
 int getPageSize()
          Return the maximum page size in rows.
 Renderable getPaginator()
          Return the paginator for rendering the table pagination.
 int getPaginatorAttachment()
          Return the paginator attachment style.
 boolean getRenderId()
          Returns the column render id attribute status.
 int getRowCount()
          The total possible number of rows of the table.
 List getRowList()
          Return the list of table rows.
 boolean getShowBanner()
          Return the show Table banner flag detailing number of rows and current rows displayed.
 boolean getSortable()
          Return the table default column are sortable status.
 String getSortedColumn()
          Return the name of the sorted column, or null if not defined.
 Object getState()
          Return the Table state.
 String getTag()
          Return the table's html tag: table.
 String getWidth()
          Return the table HTML <td> width attribute.
 boolean hasControls()
          Return true if the table has any controls defined.
 boolean isSorted()
          Return the sorted status of the table row list.
 boolean isSortedAscending()
          Return true if the sort order is ascending.
 void onDestroy()
          This method will clear the rowList, if the property nullifyRowListOnDestroy is true, set the sorted flag to false and will invoke the onDestroy() method of any child controls.
 void onInit()
          Initialize the controls contained in the Table.
 boolean onProcess()
          Process any Table paging control requests, and process any added Table Controls.
 void onRender()
          This method invokes getRowList() to ensure exceptions thrown while retrieving table rows will be handled by the error page.
 void removeColumn(Column column)
          Remove the given Column from the table.
 void removeColumn(String name)
          Remove the named column from the Table.
 void removeColumns(List<String> columnNames)
          Remove the list of named columns from the table.
 void removeState(Context context)
          Remove the Table state from the session for the given request context.
 void render(HtmlStringBuffer buffer)
          Render the HTML representation of the Table.
protected  void renderBodyNoRows(HtmlStringBuffer buffer)
          Render the table body content if no rows are in the row list.
protected  void renderBodyRowColumns(HtmlStringBuffer buffer, int rowIndex)
          Render the current table body row cells.
protected  void renderBodyRows(HtmlStringBuffer buffer)
          Render the table body rows for each of the rows in getRowList.
protected  void renderFooterRow(HtmlStringBuffer buffer)
          Render the table header footer row.
protected  void renderHeaderRow(HtmlStringBuffer buffer)
          Render the table header row of column names.
protected  void renderPaginator(HtmlStringBuffer buffer)
          Render the table pagination display.
protected  void renderPagingControls(HtmlStringBuffer buffer)
          Deprecated. use renderPaginator(HtmlStringBuffer) instead, this method is provided to support backward compatibility older Click 1.4 customized tables. In these scenarios please override renderPaginator(HtmlStringBuffer) method to invoke renderTableBanner(HtmlStringBuffer) and renderPagingControls(HtmlStringBuffer).
protected  void renderTableBanner(HtmlStringBuffer buffer)
          Deprecated. use renderPaginator(HtmlStringBuffer) instead, this method is provided to support backward compatibility older Click 1.4 customized tables. In these scenarios please override renderPaginator(HtmlStringBuffer) method to invoke renderTableBanner(HtmlStringBuffer) and renderPagingControls(HtmlStringBuffer).
 void restoreState(Context context)
          Restore the Table state from the session for the given request context.
 void saveState(Context context)
          Save the Table state to the session for the given request context.
 void setBannerPosition(int value)
          Set Table pagination banner position.
 void setCaption(String caption)
          Set the content of the table <caption> element.
 void setClass(String value)
          Set the HTML class attribute.
 void setDataProvider(DataProvider dataProvider)
          Set the table row list DataProvider.
 void setHeight(String value)
          Set the table HTML <td> height attribute.
 void setHoverRows(boolean hoverRows)
          Set whether the table row (<tr>) elements should have the class="hover" attribute set on JavaScript mouseover events.
 void setName(String name)
          Set the name of the Control.
 void setNullifyRowListOnDestroy(boolean value)
          Set the flag to nullify the rowList when the onDestroy() method is invoked.
 void setPageNumber(int pageNumber)
          Set the currently displayed page number.
 void setPageSize(int pageSize)
          Set the maximum page size in rows.
 void setPaginator(Renderable value)
          Set the paginator for rendering the table pagination controls.
 void setPaginatorAttachment(int value)
          Set Table pagination attachment style.
 void setParent(Object parent)
          Set the parent of the Table.
 void setRenderId(boolean renderId)
          Set the column render id attribute status.
 void setRowList(List rowList)
          Set the list of table rows.
 void setShowBanner(boolean showBanner)
          Set the show Table banner flag detailing number of rows and current rows displayed.
 void setSortable(boolean sortable)
          Set the table default column are sortable status.
 void setSorted(boolean value)
          Set the sorted status of the table row list.
 void setSortedAscending(boolean ascending)
          Set the ascending sort order status.
 void setSortedColumn(String columnName)
          Set the name of the sorted column, or null if not defined.
 void setState(Object state)
          Set the Table state.
 void setWidth(String value)
          Set the table HTML <td> width attribute.
protected  void sortRowList()
          The default row list sorting method, which will sort the row list based on the selected column if the row list is not already sorted.
 
Methods inherited from class org.apache.click.control.AbstractControl
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getHtmlImports, getId, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, removeBehavior, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setListener, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PAGINATOR_ATTACHED

public static final int PAGINATOR_ATTACHED
The attached style pagination banner position.

See Also:
Constant Field Values

PAGINATOR_DETACHED

public static final int PAGINATOR_DETACHED
The detached style pagination banner position.

See Also:
Constant Field Values

PAGINATOR_INLINE

public static final int PAGINATOR_INLINE
The attached style pagination banner position.

See Also:
Constant Field Values

POSITION_TOP

public static final int POSITION_TOP
The table top pagination banner position.

See Also:
Constant Field Values

POSITION_BOTTOM

public static final int POSITION_BOTTOM
The table bottom pagination banner position.

See Also:
Constant Field Values

POSITION_BOTH

public static final int POSITION_BOTH
The table top and bottom pagination banner position.

See Also:
Constant Field Values

ASCENDING

public static final String ASCENDING
The control ActionLink page number parameter name: "ascending".

See Also:
Constant Field Values

COLUMN

public static final String COLUMN
The control ActionLink sorted column parameter name: "column".

See Also:
Constant Field Values

PAGE

public static final String PAGE
The control ActionLink page number parameter name: "page".

See Also:
Constant Field Values

SORT

public static final String SORT
The control ActionLink sort number parameter name: "sort".

See Also:
Constant Field Values

CLASS_BLUE1

public static final String CLASS_BLUE1
The table CSS style: "blue1".

See Also:
Constant Field Values

CLASS_BLUE2

public static final String CLASS_BLUE2
The table CSS style: "blue2".

See Also:
Constant Field Values

CLASS_COMPLEX

public static final String CLASS_COMPLEX
The table CSS style: "complex".

See Also:
Constant Field Values

CLASS_ISI

public static final String CLASS_ISI
The table CSS style: "isi".

See Also:
Constant Field Values

CLASS_ITS

public static final String CLASS_ITS
The table CSS style: "its".

See Also:
Constant Field Values

CLASS_MARS

public static final String CLASS_MARS
The table CSS style: "mars".

See Also:
Constant Field Values

CLASS_NOCOL

public static final String CLASS_NOCOL
The table CSS style: "nocol".

See Also:
Constant Field Values

CLASS_ORANGE1

public static final String CLASS_ORANGE1
The table CSS style: "orange1".

See Also:
Constant Field Values

CLASS_ORANGE2

public static final String CLASS_ORANGE2
The table CSS style: "orange2".

See Also:
Constant Field Values

CLASS_REPORT

public static final String CLASS_REPORT
The table CSS style: "report".

See Also:
Constant Field Values

CLASS_SIMPLE

public static final String CLASS_SIMPLE
The table CSS style: "simple".

See Also:
Constant Field Values

CLASS_STYLES

public static final String[] CLASS_STYLES
The array of pre-defined table CSS class styles.


bannerPosition

protected int bannerPosition
The table pagination banner position: [ POSITION_TOP | POSITION_BOTTOM | POSITION_BOTH ]. The default position is POSITION_BOTTOM.


caption

protected String caption
The table HTML <caption> element.


columns

protected Map<String,Column> columns
The map of table columns keyed by column name.


columnList

protected List<Column> columnList
The list of table Columns.


controlLink

protected ActionLink controlLink
The table paging and sorting control action link.


controlList

protected List<Control> controlList
The list of table controls.


height

protected String height
The table HTML <td> height attribute.


dataProvider

protected DataProvider dataProvider
The table data provider.


rowCount

protected int rowCount
The total possible number of rows of the table. This value could be much larger than the number of entries in the rowList, indicating that some rows have not been loaded yet.


hoverRows

protected boolean hoverRows
The table rows set 'hover' CSS class on mouseover events flag. By default hoverRows is false.


nullifyRowListOnDestroy

protected boolean nullifyRowListOnDestroy
Deprecated. stateful pages are not supported anymore, use stateful Controls instead
Flag indicating if rowList is nullified when onDestroy() is invoked, default is true. This flag only applies to stateful pages.

See Also:
setNullifyRowListOnDestroy(boolean)

pageNumber

protected int pageNumber
The currently displayed page number. The page number is zero indexed, i.e. the page number of the first page is 0.


pageSize

protected int pageSize
The maximum page size in rows. A value of 0 means there is no maximum page size.


paginator

protected Renderable paginator
The paginator used to render the table pagination controls.


paginatorAttachment

protected int paginatorAttachment
The paginator attachment style: [ PAGINATOR_ATTACHED | PAGINATOR_DETACHED | PAGINATOR_INLINE ]. The default paginator attachment type is PAGINATOR_ATTACHED.


renderId

protected boolean renderId
The default column render id attribute status. The default value is false.


rowList

protected List rowList
The list Table rows. Please note the rowList is cleared in table onDestroy() method at the end of each request.


showBanner

protected boolean showBanner
The show table banner flag detailing number of rows and current rows displayed.


sortable

protected boolean sortable
The default column are sortable status. By default columnsSortable is false.


sorted

protected boolean sorted
The row list is sorted status. By default sorted is false.


sortedAscending

protected boolean sortedAscending
The rows list is sorted in ascending order.


sortedColumn

protected String sortedColumn
The name of the sorted column.


width

protected String width
The table HTML <td> width attribute.

Constructor Detail

Table

public Table(String name)
Create an Table for the given name.

Parameters:
name - the table name
Throws:
IllegalArgumentException - if the name is null

Table

public Table()
Create a Table with no name defined.

Please note the control's name must be defined before it is valid.

Method Detail

getTag

public String getTag()
Return the table's html tag: table.

Overrides:
getTag in class AbstractControl
Returns:
this controls html tag
See Also:
AbstractControl.getTag()

setParent

public void setParent(Object parent)
Set the parent of the Table.

Specified by:
setParent in interface Control
Overrides:
setParent in class AbstractControl
Parameters:
parent - the parent of the Table
Throws:
IllegalStateException - if AbstractControl.name is not defined
IllegalArgumentException - if the given parent instance is referencing this object: if (parent == this)
See Also:
Control.setParent(Object)

getBannerPosition

public int getBannerPosition()
Return the Table pagination banner position. Banner position values: [ POSITION_TOP | POSITION_BOTTOM | POSITION_BOTH ]. The default banner position is POSITION_BOTTOM.

Returns:
the table pagination banner position

setBannerPosition

public void setBannerPosition(int value)
Set Table pagination banner position. Banner position values: [ POSITION_TOP | POSITION_BOTTOM | POSITION_BOTH ].

Parameters:
value - the table pagination banner position

getCaption

public String getCaption()
Return the content of the table <caption> element, or null if not defined.

Returns:
the content of the table caption element, or null if not defined.

setCaption

public void setCaption(String caption)
Set the content of the table <caption> element.

Parameters:
caption - the content of the caption element.

setClass

public void setClass(String value)
Set the HTML class attribute.

Note: this method will replace the existing "class" attribute value.

Predefined table CSS classes include:

Parameters:
value - the HTML class attribute

addColumn

public Column addColumn(Column column)
Add the column to the table. The column will be added to the columns Map using its name.

Parameters:
column - the column to add to the table
Returns:
the added column
Throws:
IllegalArgumentException - if the table already contains a column with the same name, or the column name is not defined

removeColumn

public void removeColumn(Column column)
Remove the given Column from the table.

Parameters:
column - the column to remove from the table

removeColumn

public void removeColumn(String name)
Remove the named column from the Table.

Parameters:
name - the name of the column to remove from the table

removeColumns

public void removeColumns(List<String> columnNames)
Remove the list of named columns from the table.

Parameters:
columnNames - the list of column names to remove from the table

getNullifyRowListOnDestroy

public boolean getNullifyRowListOnDestroy()
Return true if the Table will nullify the rowList when the onDestroy() method is invoked.

Returns:
true if the rowList is nullified when onDestroy is invoked

setNullifyRowListOnDestroy

public void setNullifyRowListOnDestroy(boolean value)
Set the flag to nullify the rowList when the onDestroy() method is invoked.

This option only applies to stateful pages.

If this option is false, the rowList will be persisted between requests. If this option is true (the default), the rowList must be set each request.

Parameters:
value - the flag value to nullify the table rowList when onDestroy is called

getColumn

public Column getColumn(String name)
Return the Column for the given name.

Parameters:
name - the name of the column to return
Returns:
the Column for the given name

getColumnList

public List<Column> getColumnList()
Return the list of table columns.

Returns:
the list of table columns

getColumns

public Map<String,Column> getColumns()
Return the Map of table Columns, keyed on column name.

Returns:
the Map of table Columns, keyed on column name

addControl

public Control addControl(Control control)
Deprecated. use add(org.apache.click.Control) instead

Add the given Control to the table. The control will be processed when the Table is processed.

Parameters:
control - the Control to add to the table
Returns:
the added control

add

public Control add(Control control)
Add the given Control to the table. The control will be processed when the Table is processed.

Parameters:
control - the Control to add to the table
Returns:
the added control

getControls

public List<Control> getControls()
Return the list of Controls added to the table. Note table paging control will not be returned in this list.

Returns:
the list of table controls

hasControls

public boolean hasControls()
Return true if the table has any controls defined.

Returns:
true if the table has any controls defined

getControlLink

public ActionLink getControlLink()
Return the table paging and sorting control action link.

Note you can set parameters on the returned ActionLink in order to preserve state when paging or sorting columns. A common use case is to filter out Table rows on specified criteria. See here for an example.

Returns:
the table paging and sorting control action link

getDataProvider

public DataProvider getDataProvider()
Return the table row list DataProvider.

Returns:
the table row list DataProvider

setDataProvider

public void setDataProvider(DataProvider dataProvider)
Set the table row list DataProvider. The Table will retrieve its data from the DataProvider on demand.

Please note: setting the dataProvider will nullify the table rowList.

Example usage:

 public CustomerPage() {
     Table table = new Table("table");
     table.addColumn(new Column("id"));
     table.addColumn(new Column("name"));
     table.addColumn(new Column("investments"));

     table.setDataProvider(new DataProvider() {
         public List getData() {
              return getCustomerService().getCustomers();
         }
     });
 } 
For large data sets use a PagingDataProvider instead.

The Table methods getFirstRow(), getLastRow() and getPageSize() provides the necessary information to limit the rows to the selected page. For sorting, the Table methods getSortedColumn() and isSortedAscending() provides the necessary information to sort the data.

Please note: when using a PagingDataProvider, you are responsible for sorting the data, as the Table does not have access to all the data.

Example usage:

 public CustomerPage() {
     Table table = new Table("table");
     table.setPageSize(10);
     table.setShowBanner(true);
     table.setSortable(true);

     table.addColumn(new Column("id"));
     table.addColumn(new Column("name"));
     table.addColumn(new Column("investments"));

     table.setDataProvider(new PagingDataProvider() {

         public List getData() {
             int start = table.getFirstRow();
             int count = table.getPageSize();
             String sortColumn = table.getSortedColumn();
             boolean ascending = table.isSortedAscending();

             return getCustomerService().getCustomersForPage(start, count, sortColumn, ascending);
         }

         public int size() {
             return getCustomerService().getNumberOfCustomers();
         }
     });
 } 

Parameters:
dataProvider - the table row list DataProvider
See Also:
setRowList(java.util.List)

getHeight

public String getHeight()
Return the table HTML <td> height attribute.

Returns:
the table HTML <td> height attribute

setHeight

public void setHeight(String value)
Set the table HTML <td> height attribute.

Parameters:
value - the table HTML <td> height attribute

getHoverRows

public boolean getHoverRows()
Return true if the table row (<tr>) elements should have the class="hover" attribute set on JavaScript mouseover events. This class can be used to define mouse over :hover CSS pseudo classes to create table row highlight effects.

Returns:
true if table rows elements will have the class 'hover' attribute set on JavaScript mouseover events

setHoverRows

public void setHoverRows(boolean hoverRows)
Set whether the table row (<tr>) elements should have the class="hover" attribute set on JavaScript mouseover events. This class can be used to define mouse over :hover CSS pseudo classes to create table row highlight effects. For example:
 hover:hover { color: navy } 

Parameters:
hoverRows - specify whether class 'hover' rows attribute is rendered (default false).

getHeadElements

public List<Element> getHeadElements()
Return the Table HTML HEAD elements for the following resource: Additionally, the HEAD elements of the getControlLink() will also be returned.

Specified by:
getHeadElements in interface Control
Overrides:
getHeadElements in class AbstractControl
Returns:
the list of HEAD elements for the Table
See Also:
Control.getHeadElements()

setName

public void setName(String name)
Description copied from interface: Control
Set the name of the Control. Each control name must be unique in the containing Page model or the parent container.

Please note: changing the name of a Control after it has been added to its parent container is undefined. Thus it is best not to change the name of a Control once its been set.

Specified by:
setName in interface Control
Overrides:
setName in class AbstractControl
Parameters:
name - of the control
Throws:
IllegalArgumentException - if the name is null
See Also:
Control.setName(String)

getNumberPages

public int getNumberPages()
Return the number of pages to display.

Returns:
the number of pages to display

getPageNumber

public int getPageNumber()
Return the currently displayed page number. The page number is zero indexed, i.e. the page number of the first page is 0.

Returns:
the currently displayed page number

setPageNumber

public void setPageNumber(int pageNumber)
Set the currently displayed page number. The page number is zero indexed, i.e. the page number of the first page is 0.

Parameters:
pageNumber - set the currently displayed page number

getPageSize

public int getPageSize()
Return the maximum page size in rows. A page size of 0 means there is no maximum page size.

Returns:
the maximum page size in rows

getPaginator

public Renderable getPaginator()
Return the paginator for rendering the table pagination.

Returns:
the table paginator

setPaginator

public void setPaginator(Renderable value)
Set the paginator for rendering the table pagination controls.

Parameters:
value - the table paginator to set

getPaginatorAttachment

public int getPaginatorAttachment()
Return the paginator attachment style. Renderable attachment style values: [ PAGINATOR_ATTACHED | PAGINATOR_DETACHED | PAGINATOR_INLINE ]. The default paginator attachment type is PAGINATOR_ATTACHED.

Returns:
the paginator attachment style

setPaginatorAttachment

public void setPaginatorAttachment(int value)
Set Table pagination attachment style. Renderable attachment style values: [ PAGINATOR_ATTACHED | PAGINATOR_DETACHED | PAGINATOR_INLINE ].

Parameters:
value - the table pagination attachment style

setPageSize

public void setPageSize(int pageSize)
Set the maximum page size in rows. A page size of 0 means there is no maximum page size.

Parameters:
pageSize - the maximum page size in rows

getRenderId

public boolean getRenderId()
Returns the column render id attribute status. The default value is false.

Returns:
the column render id attribute status, default is false

setRenderId

public void setRenderId(boolean renderId)
Set the column render id attribute status.

Parameters:
renderId - set the column render id attribute status

getRowList

public List getRowList()
Return the list of table rows. Please note the rowList is cleared in table onDestroy() method at the end of each request.

If the rowList is null, this method delegates to createRowList() to create a new row list.

Returns:
the list of table rows

setRowList

public void setRowList(List rowList)
Set the list of table rows. Each row can either be a value object (JavaBean) or an instance of a Map.

Although possible to set the table rows directly with this method, best practice is to use a setDataProvider(org.apache.click.dataprovider.DataProvider) instead.

Please note the rowList is cleared in table onDestroy() method at the end of each request.

Parameters:
rowList - the list of table rows to set

getShowBanner

public boolean getShowBanner()
Return the show Table banner flag detailing number of rows and current rows displayed.

Returns:
the show Table banner flag

setShowBanner

public void setShowBanner(boolean showBanner)
Set the show Table banner flag detailing number of rows and current rows displayed.

Parameters:
showBanner - the show Table banner flag

getSortable

public boolean getSortable()
Return the table default column are sortable status. By default table columns are not sortable.

Returns:
the table default column are sortable status

setSortable

public void setSortable(boolean sortable)
Set the table default column are sortable status.

Parameters:
sortable - the table default column are sortable status

isSorted

public boolean isSorted()
Return the sorted status of the table row list.

Returns:
the sorted table row list status

setSorted

public void setSorted(boolean value)
Set the sorted status of the table row list.

Parameters:
value - the sorted status to set

isSortedAscending

public boolean isSortedAscending()
Return true if the sort order is ascending.

Returns:
true if the sort order is ascending

setSortedAscending

public void setSortedAscending(boolean ascending)
Set the ascending sort order status.

Parameters:
ascending - the ascending sort order status

getSortedColumn

public String getSortedColumn()
Return the name of the sorted column, or null if not defined.

Returns:
the name of the sorted column, or null if not defined

setSortedColumn

public void setSortedColumn(String columnName)
Set the name of the sorted column, or null if not defined.

Parameters:
columnName - the name of the sorted column

getState

public Object getState()
Return the Table state. The following state is returned:

Specified by:
getState in interface Stateful
Returns:
the Table state

setState

public void setState(Object state)
Set the Table state.

Specified by:
setState in interface Stateful
Parameters:
state - the Table state to set

getWidth

public String getWidth()
Return the table HTML <td> width attribute.

Returns:
the table HTML <td> width attribute

setWidth

public void setWidth(String value)
Set the table HTML <td> width attribute.

Parameters:
value - the table HTML <td> width attribute

getRowCount

public final int getRowCount()
The total possible number of rows of the table. This value could be much larger than the number of entries in the rowList, indicating that some rows have not been loaded yet.

This property is automatically set by the table to the appropriate value.

Returns:
the total possible number of rows of the table

getFirstRow

public int getFirstRow()
Return the index of the first row to display. Index starts from 0.

Note: page size must be set for this method to correctly calculate the first row, otherwise this method will return 0.

Returns:
the index of the first row to display

getLastRow

public int getLastRow()
Return the index of the last row to display. Index starts from 0.

Note: the Table row list and page size must be set for this method to correctly calculate the last row, otherwise this method will return 0.

Returns:
the index of the last row to display

onInit

public void onInit()
Initialize the controls contained in the Table.

Specified by:
onInit in interface Control
Overrides:
onInit in class AbstractControl
See Also:
Control.onInit()

onRender

public void onRender()
This method invokes getRowList() to ensure exceptions thrown while retrieving table rows will be handled by the error page.

Specified by:
onRender in interface Control
Overrides:
onRender in class AbstractControl
See Also:
Control.onRender()

onProcess

public boolean onProcess()
Process any Table paging control requests, and process any added Table Controls.

Specified by:
onProcess in interface Control
Overrides:
onProcess in class AbstractControl
Returns:
true to continue Page event processing or false otherwise
See Also:
Control.onProcess()

onDestroy

public void onDestroy()
This method will clear the rowList, if the property nullifyRowListOnDestroy is true, set the sorted flag to false and will invoke the onDestroy() method of any child controls.

Specified by:
onDestroy in interface Control
Overrides:
onDestroy in class AbstractControl
See Also:
Control.onDestroy()

getControlSizeEst

public int getControlSizeEst()
Description copied from class: AbstractControl
Return the estimated rendered control size in characters.

Overrides:
getControlSizeEst in class AbstractControl
Returns:
the estimated rendered control size in characters
See Also:
AbstractControl.getControlSizeEst()

render

public void render(HtmlStringBuffer buffer)
Render the HTML representation of the Table.

Specified by:
render in interface Control
Overrides:
render in class AbstractControl
Parameters:
buffer - the specified buffer to render the control's output to
See Also:
AbstractControl.toString()

removeState

public void removeState(Context context)
Remove the Table state from the session for the given request context.

Parameters:
context - the request context
See Also:
saveState(org.apache.click.Context), restoreState(org.apache.click.Context)

restoreState

public void restoreState(Context context)
Restore the Table state from the session for the given request context.

This method delegates to setState(java.lang.Object) to set the table restored state.

Parameters:
context - the request context
See Also:
saveState(org.apache.click.Context), removeState(org.apache.click.Context)

saveState

public void saveState(Context context)
Save the Table state to the session for the given request context.

* This method delegates to getState() to retrieve the table state to save.

Parameters:
context - the request context
See Also:
restoreState(org.apache.click.Context), removeState(org.apache.click.Context)

createRowList

protected List<Object> createRowList()
Create a new table row list. If a dataProvider is specified the new row list will be populated from the data provider.

Returns:
a new table row list

renderHeaderRow

protected void renderHeaderRow(HtmlStringBuffer buffer)
Render the table header row of column names.

Parameters:
buffer - the StringBuffer to render the header row in

renderBodyRows

protected void renderBodyRows(HtmlStringBuffer buffer)
Render the table body rows for each of the rows in getRowList.

Parameters:
buffer - the StringBuffer to render the table body rows in

addRowAttributes

protected void addRowAttributes(Map<String,String> attributes,
                                Object row,
                                int rowIndex)
Override this method to set HTML attributes for each Table row.

For example:

 public CompanyPage extends BorderPage {

     public void onInit() {
         table = new Table() {
             public void addRowAttributes(Map attributes, Object row, int rowIndex) {
                 Customer customer = (Customer) row;
                 if (customer.isDisabled()) {
                     // Set the row class to disabled. CSS can then be used
                     // to set disabled rows background to a different color.
                     attributes.put("class", "disabled");
                 }
                 attributes.put("onclick", "alert('you clicked on row "
                     + rowIndex + "')");
             }
         };
     }
 } 
Please note that in order to enable alternate background colors for rows, Click will automatically add a CSS class attribute to each row with a value of either odd or even. You are free to add other CSS class attributes as illustrated in the example above.

Parameters:
attributes - the row attributes
row - the domain object currently being rendered
rowIndex - the rows index

renderFooterRow

protected void renderFooterRow(HtmlStringBuffer buffer)
Render the table header footer row. This method is designed to be overridden by Table subclasses which include a custom footer row.

By default this method does not render a table footer.

An example:

 private Table table;

 public void onInit() {
     table = new Table("table") {
         public void renderFooterRow(HtmlStringBuffer buffer) {
             double totalHoldings = getCustomerService().getTotalHoldings(customers);
             renderTotalHoldingsFooter(buffer);
         };
     }
     addControl(table);
     ...
 }

 ...

 public void renderTotalHoldingsFooter(HtmlStringBuffer buffer,) {
     double total = 0;
     for (int i = 0; i < table.getRowList().size(); i++) {
         Customer customer = (Customer) table.getRowList().get(i);
         if (customer.getHoldings() != null) {
             total += customer.getHoldings().doubleValue();
         }
     }

     String format = "<b>Total Holdings</b>:   ${0,number,#,##0.00}";
     String totalDisplay = MessageFormat.format(format, new Object[] { new Double(total) });

     buffer.append("<foot><tr><td colspan='4' style='text-align:right'>");
     buffer.append(totalDisplay);
     buffer.append("</td></tr></tfoot>");
 }
 

Parameters:
buffer - the StringBuffer to render the footer row in

renderBodyRowColumns

protected void renderBodyRowColumns(HtmlStringBuffer buffer,
                                    int rowIndex)
Render the current table body row cells.

Parameters:
buffer - the StringBuffer to render the table row cells in
rowIndex - the 0-based index in tableRows to render

renderBodyNoRows

protected void renderBodyNoRows(HtmlStringBuffer buffer)
Render the table body content if no rows are in the row list.

Parameters:
buffer - the StringBuffer to render the no row message to

renderPaginator

protected void renderPaginator(HtmlStringBuffer buffer)
Render the table pagination display.

Parameters:
buffer - the StringBuffer to render the pagination display to

renderTableBanner

protected void renderTableBanner(HtmlStringBuffer buffer)
Deprecated. use renderPaginator(HtmlStringBuffer) instead, this method is provided to support backward compatibility older Click 1.4 customized tables. In these scenarios please override renderPaginator(HtmlStringBuffer) method to invoke renderTableBanner(HtmlStringBuffer) and renderPagingControls(HtmlStringBuffer).

Render the table banner detailing number of rows and number displayed.

See the /click-controls.properties for the HTML templates: table-page-banner and table-page-banner-nolinks

Parameters:
buffer - the StringBuffer to render the paging controls to

renderPagingControls

protected void renderPagingControls(HtmlStringBuffer buffer)
Deprecated. use renderPaginator(HtmlStringBuffer) instead, this method is provided to support backward compatibility older Click 1.4 customized tables. In these scenarios please override renderPaginator(HtmlStringBuffer) method to invoke renderTableBanner(HtmlStringBuffer) and renderPagingControls(HtmlStringBuffer).

Render the table paging action link controls.

See the /click-controls.properties for the HTML templates: table-page-links and table-page-links-nobanner

Parameters:
buffer - the StringBuffer to render the paging controls to

sortRowList

protected void sortRowList()
The default row list sorting method, which will sort the row list based on the selected column if the row list is not already sorted.