net.sf.click.control
Class Table

java.lang.Object
  extended bynet.sf.click.control.AbstractControl
      extended bynet.sf.click.control.Table
All Implemented Interfaces:
Control, Serializable

public class Table
extends AbstractControl

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);
     }

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

     public void onRender() {
         List customers = getCustomerService().getCustomersSortedByName();
         table.setRowList(customers);
     }
 } 

Table Styles

The Table control automatically deploys the table CSS style sheet (table.css) to the application directory /click. To import the Table CSS styles and any control JavaScript simply reference $cssImports and $jsImports in the page template. For example:
 <html>
 <head>
 $cssImports
 </head>
 <body>
 $table
 </body>
 </html>
 $jsImports
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 and Sorting

Table provides out-of-the-box paging and sorting.

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

To enable/disable sorting use setSortable(boolean).

You can also set parameters on links generated by the Table through the Table's controlLink.

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

For example:

 public CompanyPage extends BorderPage {

      // companyId is the criteria used to limit Table rows to clients from
      // the specified company
      public String companyId;

      public Table table = new Table();

      public onInit() {
          // companyId could be selected from a drop down list or similar means.
          // Set the companyId on the table's controlLink. If you view the
          // output rendered by Table you will note the companyId parameter
          // is rendered for each Paging and Sorting link.
          table.getControlLink().setParameter("companyId", companyId);
      }

      ...

      public void onRender() {
          // Select only clients for the specified companyId
          List rowList = getCompanyDao().getCompanyClients(companyId);
          table.setRowList(rowList);
      }
 } 
Table supports rendering different paginators through the method setPaginator(net.sf.click.control.Renderable). The default Table Paginator is TablePaginator.

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).

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

Author:
Malcolm Edgar
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 ].
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 columnList
          The list of table Columns.
protected  Map columns
          The map of table columns keyed by column name.
protected  ActionLink controlLink
          The table paging and sorting control action link.
protected  List controlList
          The list of table controls.
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
          Flag indicating if rowList is nullified when onDestroy() is invoked, default is true.
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_DEATTACHED | 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  List rowList
          The list Table rows.
protected  boolean showBanner
          The show table banner flag detailing number of rows and 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.
static String TABLE_IMPORTS_DARK
          The table.css style sheet import link with a dark contract sortable icon.
static String TABLE_IMPORTS_LIGHT
          The table.css style sheet import link with a light contract sortable icon.
protected  String width
          The table HTML <td> width attribute.
 
Fields inherited from class net.sf.click.control.AbstractControl
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles
 
Fields inherited from interface net.sf.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)
          Add the given Control to the table.
protected  void addRowAttributes(Map attributes, Object row, int rowIndex)
          Override this method to set HTML attributes for each Table row.
 int getBannerPosition()
          Return the Table pagination banner position.
 Column getColumn(String name)
          Return the Column for the given name.
 List getColumnList()
          Return the list of table columns.
 Map getColumns()
          Return the Map of table Columns, keyed on column name.
 ActionLink getControlLink()
          Return the table paging and sorting control action link.
 List getControls()
          Return the list of Controls added to the table.
 int getControlSizeEst()
          Return the estimated rendered control size in characters.
protected  int getFirstRow()
          Return the index of the first row to display.
 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.
 String getHtmlImports()
          Return the HTML head import statements for the CSS stylesheet file: click/table.css.
protected  int getLastRow()
          Return the index of the last row to diplay.
 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.
 List getRowList()
          Return the list of table rows.
 boolean getShowBanner()
          Return the show Table banner flag detailing number of rows and 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.
 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 onDeploy(ServletContext servletContext)
          Deploy the table.css and column sorting icon files to the click web directory when the application is initialized.
 void onDestroy()
          This method will clear the rowList, if the property clearRowListOnDestroy 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()
          Perform any pre rendering logic.
 void removeColumn(Column column)
          Remove the given Column from the table.
 void removeColumn(String name)
          Remove the named colum from the Table.
 void removeColumns(List columnNames)
          Remove the list of named columns from the table.
 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 setBannerPosition(int value)
          Set Table pagination banner position.
 void setClass(String value)
          Set the HTML class attribute.
 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 setListener(Object listener, String method)
          Set the controls event listener.
 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 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 value)
          Set the ascending sort order status.
 void setSortedColumn(String value)
          Set the name of the sorted column, or null if not defined.
 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 net.sf.click.control.AbstractControl
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getId, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, registerActionEvent, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setStyle, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TABLE_IMPORTS_LIGHT

public static final String TABLE_IMPORTS_LIGHT
The table.css style sheet import link with a light contract sortable icon.

See Also:
Constant Field Values

TABLE_IMPORTS_DARK

public static final String TABLE_IMPORTS_DARK
The table.css style sheet import link with a dark contract sortable icon.

See Also:
Constant Field Values

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.


columns

protected Map columns
The map of table columns keyed by column name.


columnList

protected List columnList
The list of table Columns.


controlLink

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


controlList

protected List controlList
The list of table controls.


height

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


hoverRows

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


nullifyRowListOnDestroy

protected boolean nullifyRowListOnDestroy
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_DEATTACHED | 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 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

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 colum from the Table.

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

removeColumns

public void removeColumns(List 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 getColumnList()
Return the list of table columns.

Returns:
the list of table columns

getColumns

public Map 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)
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 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

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 highlite 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 highlite effects. For example:
 hover:hover { color: navy } 

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

getHtmlImports

public String getHtmlImports()
Return the HTML head import statements for the CSS stylesheet file: click/table.css.

Specified by:
getHtmlImports in interface Control
Overrides:
getHtmlImports in class AbstractControl
Returns:
the HTML head import statements for the control stylesheet
See Also:
Control.getHtmlImports()

setListener

public void setListener(Object listener,
                        String method)
Description copied from class: AbstractControl
Set the controls event listener.

The method signature of the listener is:

An example event listener method would be:

 public boolean onClick() {
     System.out.println("onClick called");
     return true;
 } 

Specified by:
setListener in interface Control
Overrides:
setListener in class AbstractControl
Parameters:
listener - the listener object with the named method to invoke
method - the name of the method to invoke
See Also:
Control.setListener(Object, String)

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_DEATTACHED | 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_DEATTACHED | 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.

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.

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 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 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 value)
Set the ascending sort order status.

Parameters:
value - 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 value)
Set the name of the sorted column, or null if not defined.

Parameters:
value - the the name of the sorted column

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

onDeploy

public void onDeploy(ServletContext servletContext)
Deploy the table.css and column sorting icon files to the click web directory when the application is initialized.

Specified by:
onDeploy in interface Control
Overrides:
onDeploy in class AbstractControl
Parameters:
servletContext - the servlet context
See Also:
Control.onDeploy(ServletContext)

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()
Perform any pre rendering logic.

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 clearRowListOnDestroy 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()

getFirstRow

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

Returns:
the index of the first row to display

getLastRow

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

Returns:
the index of the last row to display

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 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 domain, int rowIndex) {
                 Customer customer = (Customer) customer;
                 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.properies 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.properies 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.