|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.control.AbstractControl net.sf.click.control.Table
Provides a HTML Table control: <table>.
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); } }
<html> <head> $cssImports </head> <body> $table </body> </html> $jsImportsThe table CSS style sheet is adapted from the DisplayTag screen.css style sheet and includes the styles:
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
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
.
addRowAttributes(java.util.Map, java.lang.Object, int)
.
See also W3C HTML reference
Tables
and the W3C CSS reference
Tables.
Column
,
Decorator
,
Serialized FormField 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 |
public static final String TABLE_IMPORTS_LIGHT
public static final String TABLE_IMPORTS_DARK
public static final int PAGINATOR_ATTACHED
public static final int PAGINATOR_DETACHED
public static final int PAGINATOR_INLINE
public static final int POSITION_TOP
public static final int POSITION_BOTTOM
public static final int POSITION_BOTH
public static final String ASCENDING
public static final String COLUMN
public static final String PAGE
public static final String SORT
public static final String CLASS_BLUE1
public static final String CLASS_BLUE2
public static final String CLASS_COMPLEX
public static final String CLASS_ISI
public static final String CLASS_ITS
public static final String CLASS_MARS
public static final String CLASS_NOCOL
public static final String CLASS_ORANGE1
public static final String CLASS_ORANGE2
public static final String CLASS_REPORT
public static final String CLASS_SIMPLE
public static final String[] CLASS_STYLES
protected int bannerPosition
protected Map columns
protected List columnList
protected ActionLink controlLink
protected List controlList
protected String height
protected boolean hoverRows
protected boolean nullifyRowListOnDestroy
setNullifyRowListOnDestroy(boolean)
protected int pageNumber
protected int pageSize
protected Renderable paginator
protected int paginatorAttachment
protected boolean renderId
protected List rowList
onDestroy()
method at the end of each request.
protected boolean showBanner
protected boolean sortable
protected boolean sorted
protected boolean sortedAscending
protected String sortedColumn
protected String width
Constructor Detail |
public Table(String name)
name
- the table name
IllegalArgumentException
- if the name is nullpublic Table()
Method Detail |
public String getTag()
getTag
in class AbstractControl
AbstractControl.getTag()
public void setParent(Object parent)
setParent
in interface Control
setParent
in class AbstractControl
parent
- the parent of the Table
IllegalStateException
- if AbstractControl.name
is not defined
IllegalArgumentException
- if the given parent instance is
referencing this object: if (parent == this)Control.setParent(Object)
public int getBannerPosition()
public void setBannerPosition(int value)
value
- the table pagination banner positionpublic void setClass(String value)
value
- the HTML class attributepublic Column addColumn(Column column)
columns
Map using its name.
column
- the column to add to the table
IllegalArgumentException
- if the table already contains a column
with the same name, or the column name is not definedpublic void removeColumn(Column column)
column
- the column to remove from the tablepublic void removeColumn(String name)
name
- the name of the column to remove from the tablepublic void removeColumns(List columnNames)
columnNames
- the list of column names to remove from the tablepublic boolean getNullifyRowListOnDestroy()
public void setNullifyRowListOnDestroy(boolean value)
value
- the flag value to nullify the table rowList when onDestroy
is calledpublic Column getColumn(String name)
name
- the name of the column to return
public List getColumnList()
public Map getColumns()
public Control addControl(Control control)
control
- the Control to add to the table
public Control add(Control control)
control
- the Control to add to the table
public List getControls()
public boolean hasControls()
public ActionLink getControlLink()
public String getHeight()
public void setHeight(String value)
value
- the table HTML <td> height attributepublic boolean getHoverRows()
public void setHoverRows(boolean hoverRows)
hover:hover { color: navy }
hoverRows
- specify whether class 'hover' rows attribute is rendered (default false).public String getHtmlImports()
getHtmlImports
in interface Control
getHtmlImports
in class AbstractControl
Control.getHtmlImports()
public void setListener(Object listener, String method)
AbstractControl
public boolean onClick() { System.out.println("onClick called"); return true; }
setListener
in interface Control
setListener
in class AbstractControl
listener
- the listener object with the named method to invokemethod
- the name of the method to invokeControl.setListener(Object, String)
public void setName(String name)
Control
setName
in interface Control
setName
in class AbstractControl
name
- of the control
IllegalArgumentException
- if the name is nullControl.setName(String)
public int getNumberPages()
public int getPageNumber()
public void setPageNumber(int pageNumber)
pageNumber
- set the currently displayed page numberpublic int getPageSize()
public Renderable getPaginator()
public void setPaginator(Renderable value)
value
- the table paginator to setpublic int getPaginatorAttachment()
public void setPaginatorAttachment(int value)
value
- the table pagination attachment stylepublic void setPageSize(int pageSize)
pageSize
- the maximum page size in rowspublic boolean getRenderId()
public void setRenderId(boolean renderId)
renderId
- set the column render id attribute statuspublic List getRowList()
onDestroy()
method at the end of each request.
public void setRowList(List rowList)
onDestroy()
method
at the end of each request.
rowList
- the list of table rows to setpublic boolean getShowBanner()
public void setShowBanner(boolean showBanner)
showBanner
- the show Table banner flagpublic boolean getSortable()
public void setSortable(boolean sortable)
sortable
- the table default column are sortable statuspublic boolean isSorted()
public void setSorted(boolean value)
value
- the sorted status to setpublic boolean isSortedAscending()
public void setSortedAscending(boolean value)
value
- the ascending sort order statuspublic String getSortedColumn()
public void setSortedColumn(String value)
value
- the the name of the sorted columnpublic String getWidth()
public void setWidth(String value)
value
- the table HTML <td> width attributepublic void onDeploy(ServletContext servletContext)
onDeploy
in interface Control
onDeploy
in class AbstractControl
servletContext
- the servlet contextControl.onDeploy(ServletContext)
public void onInit()
onInit
in interface Control
onInit
in class AbstractControl
Control.onInit()
public void onRender()
onRender
in interface Control
onRender
in class AbstractControl
Control.onRender()
public boolean onProcess()
onProcess
in interface Control
onProcess
in class AbstractControl
Control.onProcess()
public void onDestroy()
onDestroy
in interface Control
onDestroy
in class AbstractControl
Control.onDestroy()
public int getControlSizeEst()
AbstractControl
getControlSizeEst
in class AbstractControl
AbstractControl.getControlSizeEst()
public void render(HtmlStringBuffer buffer)
render
in interface Control
render
in class AbstractControl
buffer
- the specified buffer to render the control's output toAbstractControl.toString()
protected int getFirstRow()
protected int getLastRow()
protected void renderHeaderRow(HtmlStringBuffer buffer)
buffer
- the StringBuffer to render the header row inprotected void renderBodyRows(HtmlStringBuffer buffer)
buffer
- the StringBuffer to render the table body rows inprotected void addRowAttributes(Map attributes, Object row, int rowIndex)
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.
attributes
- the row attributesrow
- the domain object currently being renderedrowIndex
- the rows indexprotected void renderFooterRow(HtmlStringBuffer buffer)
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>"); }
buffer
- the StringBuffer to render the footer row inprotected void renderBodyRowColumns(HtmlStringBuffer buffer, int rowIndex)
buffer
- the StringBuffer to render the table row cells inrowIndex
- the 0-based index in tableRows to renderprotected void renderBodyNoRows(HtmlStringBuffer buffer)
buffer
- the StringBuffer to render the no row message toprotected void renderPaginator(HtmlStringBuffer buffer)
buffer
- the StringBuffer to render the pagination display toprotected void renderTableBanner(HtmlStringBuffer buffer)
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)
.
buffer
- the StringBuffer to render the paging controls toprotected void renderPagingControls(HtmlStringBuffer buffer)
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)
.
buffer
- the StringBuffer to render the paging controls toprotected void sortRowList()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |