Class Table
- java.lang.Object
-
- org.openidentityplatform.openam.click.control.AbstractControl
-
- org.openidentityplatform.openam.click.control.Table
-
- All Implemented Interfaces:
Serializable,org.apache.click.Stateful,org.openidentityplatform.openam.click.Control
public class Table extends AbstractControl implements org.apache.click.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.Example
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 aDataProvideris used to populate the Tablerow listfrom. DataProviders are used to provide data on demand to controls. For verylarge data setsuse aPagingDataProviderinstead. 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):click/table.css
<html> <head> $headElements </head> <body> $table $jsElements </body> </html>
Table Styles
The table CSS style sheet is adapted from the DisplayTagscreen.cssstyle sheet and includes the styles:- blue1
- blue2
- complex
- isi
- its
- mars
- nocol
- orange1
- orange2
- report
- simple
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 atable-default-classmessage property in your applicationsclick-pages.propertiesfile. 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 isTablePaginator.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 methodaddRowAttributes(Map, Object, int)and add custom attributes to the row's attribute Map.Large Datasets
For large data sets use aPagingDataProvider.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 rowsrepresented by the PagingDataProvider.The Table methods
getFirstRow(),getLastRow()andgetPageSize()provides the necessary information to limit the rows to the selected page. For sorting, the Table methodsgetSortedColumn()andisSortedAscending()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
Fields Modifier and Type Field Description static StringASCENDINGThe control ActionLink page number parameter name:"ascending".protected intbannerPositionThe table pagination banner position:[ POSITION_TOP | POSITION_BOTTOM | POSITION_BOTH ].protected StringcaptionThe table HTML <caption> element.static StringCLASS_BLUE1The table CSS style:"blue1".static StringCLASS_BLUE2The table CSS style:"blue2".static StringCLASS_COMPLEXThe table CSS style:"complex".static StringCLASS_ISIThe table CSS style:"isi".static StringCLASS_ITSThe table CSS style:"its".static StringCLASS_MARSThe table CSS style:"mars".static StringCLASS_NOCOLThe table CSS style:"nocol".static StringCLASS_ORANGE1The table CSS style:"orange1".static StringCLASS_ORANGE2The table CSS style:"orange2".static StringCLASS_REPORTThe table CSS style:"report".static StringCLASS_SIMPLEThe table CSS style:"simple".static String[]CLASS_STYLESThe array of pre-defined table CSS class styles.static StringCOLUMNThe control ActionLink sorted column parameter name:"column".protected List<Column>columnListThe list of table Columns.protected Map<String,Column>columnsThe map of table columns keyed by column name.protected ActionLinkcontrolLinkThe table paging and sorting control action link.protected List<org.openidentityplatform.openam.click.Control>controlListThe list of table controls.protected org.apache.click.dataprovider.DataProviderdataProviderThe table data provider.protected StringheightThe table HTML <td> height attribute.protected booleanhoverRowsThe table rows set 'hover' CSS class on mouseover events flag.protected booleannullifyRowListOnDestroyDeprecated.stateful pages are not supported anymore, use stateful Controls insteadstatic StringPAGEThe control ActionLink page number parameter name:"page".protected intpageNumberThe currently displayed page number.protected intpageSizeThe maximum page size in rows.protected RenderablepaginatorThe paginator used to render the table pagination controls.static intPAGINATOR_ATTACHEDThe attached style pagination banner position.static intPAGINATOR_DETACHEDThe detached style pagination banner position.static intPAGINATOR_INLINEThe attached style pagination banner position.protected intpaginatorAttachmentThe paginator attachment style:[ PAGINATOR_ATTACHED | PAGINATOR_DETACHED | PAGINATOR_INLINE ].static intPOSITION_BOTHThe table top and bottom pagination banner position.static intPOSITION_BOTTOMThe table bottom pagination banner position.static intPOSITION_TOPThe table top pagination banner position.protected booleanrenderIdThe default column render id attribute status.protected introwCountThe total possible number of rows of the table.protected ListrowListThe list Table rows.protected booleanshowBannerThe show table banner flag detailing number of rows and current rows displayed.static StringSORTThe control ActionLink sort number parameter name:"sort".protected booleansortableThe default column are sortable status.protected booleansortedThe row list is sorted status.protected booleansortedAscendingThe rows list is sorted in ascending order.protected StringsortedColumnThe name of the sorted column.protected StringwidthThe table HTML <td> width attribute.-
Fields inherited from class org.openidentityplatform.openam.click.control.AbstractControl
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description org.openidentityplatform.openam.click.Controladd(org.openidentityplatform.openam.click.Control control)Add the given Control to the table.ColumnaddColumn(Column column)Add the column to the table.org.openidentityplatform.openam.click.ControladdControl(org.openidentityplatform.openam.click.Control control)Deprecated.useadd(Control)insteadprotected voidaddRowAttributes(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.intgetBannerPosition()Return the Table pagination banner position.StringgetCaption()Return the content of the table<caption>element, or null if not defined.ColumngetColumn(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.ActionLinkgetControlLink()Return the table paging and sorting control action link.List<org.openidentityplatform.openam.click.Control>getControls()Return the list of Controls added to the table.intgetControlSizeEst()Return the estimated rendered control size in characters.org.apache.click.dataprovider.DataProvidergetDataProvider()Return the table row list DataProvider.intgetFirstRow()Return the index of the first row to display.List<Element>getHeadElements()Return the Table HTML HEAD elements for the following resource:click/table.cssAdditionally, the HEAD elements of thegetControlLink()will also be returned.StringgetHeight()Return the table HTML <td> height attribute.booleangetHoverRows()Return true if the table row (<tr>) elements should have the class="hover" attribute set on JavaScript mouseover events.intgetLastRow()Return the index of the last row to display.booleangetNullifyRowListOnDestroy()Return true if the Table will nullify therowListwhen theonDestroy()method is invoked.intgetNumberPages()Return the number of pages to display.intgetPageNumber()Return the currently displayed page number.intgetPageSize()Return the maximum page size in rows.RenderablegetPaginator()Return the paginator for rendering the table pagination.intgetPaginatorAttachment()Return the paginator attachment style.booleangetRenderId()Returns the column render id attribute status.intgetRowCount()The total possible number of rows of the table.ListgetRowList()Return the list of table rows.booleangetShowBanner()Return the show Table banner flag detailing number of rows and current rows displayed.booleangetSortable()Return the table default column are sortable status.StringgetSortedColumn()Return the name of the sorted column, or null if not defined.ObjectgetState()Return the Table state.StringgetTag()Return the table's html tag:table.StringgetWidth()Return the table HTML <td> width attribute.booleanhasControls()Return true if the table has any controls defined.booleanisSorted()Return the sorted status of the table row list.booleanisSortedAscending()Return true if the sort order is ascending.voidonDestroy()This method will clear therowList, if the propertynullifyRowListOnDestroyis true, set the sorted flag to false and will invoke the onDestroy() method of any child controls.voidonInit()Initialize the controls contained in the Table.booleanonProcess()Process any Table paging control requests, and process any added Table Controls.voidonRender()This method invokesgetRowList()to ensure exceptions thrown while retrieving table rows will be handled by the error page.voidremoveColumn(String name)Remove the named column from the Table.voidremoveColumn(Column column)Remove the given Column from the table.voidremoveColumns(List<String> columnNames)Remove the list of named columns from the table.voidremoveState(org.openidentityplatform.openam.click.Context context)Remove the Table state from the session for the given request context.voidrender(HtmlStringBuffer buffer)Render the HTML representation of the Table.protected voidrenderBodyNoRows(HtmlStringBuffer buffer)Render the table body content if no rows are in the row list.protected voidrenderBodyRowColumns(HtmlStringBuffer buffer, int rowIndex)Render the current table body row cells.protected voidrenderBodyRows(HtmlStringBuffer buffer)Render the table body rows for each of the rows ingetRowList.protected voidrenderFooterRow(HtmlStringBuffer buffer)Render the table header footer row.protected voidrenderHeaderRow(HtmlStringBuffer buffer)Render the table header row of column names.protected voidrenderPaginator(HtmlStringBuffer buffer)Render the table pagination display.protected voidrenderPagingControls(HtmlStringBuffer buffer)Deprecated.userenderPaginator(HtmlStringBuffer)instead, this method is provided to support backward compatibility older Click 1.4 customized tables.protected voidrenderTableBanner(HtmlStringBuffer buffer)Deprecated.userenderPaginator(HtmlStringBuffer)instead, this method is provided to support backward compatibility older Click 1.4 customized tables.voidrestoreState(org.openidentityplatform.openam.click.Context context)Restore the Table state from the session for the given request context.voidsaveState(org.openidentityplatform.openam.click.Context context)Save the Table state to the session for the given request context.voidsetBannerPosition(int value)Set Table pagination banner position.voidsetCaption(String caption)Set the content of the table<caption>element.voidsetClass(String value)Set the HTML class attribute.voidsetDataProvider(org.apache.click.dataprovider.DataProvider dataProvider)Set the table row listDataProvider.voidsetHeight(String value)Set the table HTML <td> height attribute.voidsetHoverRows(boolean hoverRows)Set whether the table row (<tr>) elements should have the class="hover" attribute set on JavaScript mouseover events.voidsetName(String name)Set the name of the Control.voidsetNullifyRowListOnDestroy(boolean value)Set the flag to nullify therowListwhen theonDestroy()method is invoked.voidsetPageNumber(int pageNumber)Set the currently displayed page number.voidsetPageSize(int pageSize)Set the maximum page size in rows.voidsetPaginator(Renderable value)Set the paginator for rendering the table pagination controls.voidsetPaginatorAttachment(int value)Set Table pagination attachment style.voidsetParent(Object parent)Set the parent of the Table.voidsetRenderId(boolean renderId)Set the column render id attribute status.voidsetRowList(List rowList)Set the list of table rows.voidsetShowBanner(boolean showBanner)Set the show Table banner flag detailing number of rows and current rows displayed.voidsetSortable(boolean sortable)Set the table default column are sortable status.voidsetSorted(boolean value)Set the sorted status of the table row list.voidsetSortedAscending(boolean ascending)Set the ascending sort order status.voidsetSortedColumn(String columnName)Set the name of the sorted column, or null if not defined.voidsetState(Object state)Set the Table state.voidsetWidth(String value)Set the table HTML <td> width attribute.protected voidsortRowList()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.openidentityplatform.openam.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
-
-
-
-
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 isPOSITION_BOTTOM.
-
caption
protected String caption
The table HTML <caption> element.
-
controlLink
protected ActionLink controlLink
The table paging and sorting control action link.
-
controlList
protected List<org.openidentityplatform.openam.click.Control> controlList
The list of table controls.
-
height
protected String height
The table HTML <td> height attribute.
-
dataProvider
protected org.apache.click.dataprovider.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 therowList, 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 insteadFlag indicating ifrowListis nullified whenonDestroy()is invoked, default is true. This flag only applies tostatefulpages.- 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 isPAGINATOR_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 tableonDestroy()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:
getTagin classAbstractControl- Returns:
- this controls html tag
- See Also:
AbstractControl.getTag()
-
setParent
public void setParent(Object parent)
Set the parent of the Table.- Specified by:
setParentin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
setParentin classAbstractControl- Parameters:
parent- the parent of the Table- Throws:
IllegalStateException- ifAbstractControl.nameis not definedIllegalArgumentException- if the given parent instance is referencingthisobject: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 isPOSITION_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
nullif 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:
- complex
- isi
- its
- mars
- nocol
- report
- simple
- Parameters:
value- the HTML class attribute
-
addColumn
public Column addColumn(Column column)
Add the column to the table. The column will be added to thecolumnsMap 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 therowListwhen theonDestroy()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 therowListwhen theonDestroy()method is invoked.This option only applies to
statefulpages.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 org.openidentityplatform.openam.click.Control addControl(org.openidentityplatform.openam.click.Control control)
Deprecated.useadd(Control)insteadAdd 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 org.openidentityplatform.openam.click.Control add(org.openidentityplatform.openam.click.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<org.openidentityplatform.openam.click.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 org.apache.click.dataprovider.DataProvider getDataProvider()
Return the table row list DataProvider.- Returns:
- the table row list DataProvider
-
setDataProvider
public void setDataProvider(org.apache.click.dataprovider.DataProvider dataProvider)
Set the table row listDataProvider. 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 aPagingDataProviderinstead.The Table methods
getFirstRow(),getLastRow()andgetPageSize()provides the necessary information to limit the rows to the selected page. For sorting, the Table methodsgetSortedColumn()andisSortedAscending()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(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:click/table.css
getControlLink()will also be returned.- Specified by:
getHeadElementsin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
getHeadElementsin classAbstractControl- Returns:
- the list of HEAD elements for the Table
- See Also:
Control.getHeadElements()
-
setName
public void setName(String name)
Description copied from interface:org.openidentityplatform.openam.click.ControlSet 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:
setNamein interfaceorg.openidentityplatform.openam.click.Control- Overrides:
setNamein classAbstractControl- 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 isPAGINATOR_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 tableonDestroy()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 aMap.Although possible to set the table rows directly with this method, best practice is to use a
setDataProvider(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:
getStatein interfaceorg.apache.click.Stateful- Returns:
- the Table state
-
setState
public void setState(Object state)
Set the Table state.- Specified by:
setStatein interfaceorg.apache.click.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 therowList, 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 sizemust 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 listandpage sizemust 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:
onInitin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
onInitin classAbstractControl- See Also:
Control.onInit()
-
onRender
public void onRender()
This method invokesgetRowList()to ensure exceptions thrown while retrieving table rows will be handled by the error page.- Specified by:
onRenderin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
onRenderin classAbstractControl- See Also:
Control.onRender()
-
onProcess
public boolean onProcess()
Process any Table paging control requests, and process any added Table Controls.- Specified by:
onProcessin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
onProcessin classAbstractControl- Returns:
- true to continue Page event processing or false otherwise
- See Also:
Control.onProcess()
-
onDestroy
public void onDestroy()
This method will clear therowList, if the propertynullifyRowListOnDestroyis true, set the sorted flag to false and will invoke the onDestroy() method of any child controls.- Specified by:
onDestroyin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
onDestroyin classAbstractControl- See Also:
Control.onDestroy()
-
getControlSizeEst
public int getControlSizeEst()
Description copied from class:AbstractControlReturn the estimated rendered control size in characters.- Overrides:
getControlSizeEstin classAbstractControl- 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:
renderin interfaceorg.openidentityplatform.openam.click.Control- Overrides:
renderin classAbstractControl- Parameters:
buffer- the specified buffer to render the control's output to- See Also:
AbstractControl.toString()
-
removeState
public void removeState(org.openidentityplatform.openam.click.Context context)
Remove the Table state from the session for the given request context.- Parameters:
context- the request context- See Also:
saveState(Context),restoreState(Context)
-
restoreState
public void restoreState(org.openidentityplatform.openam.click.Context context)
Restore the Table state from the session for the given request context.This method delegates to
setState(Object)to set the table restored state.- Parameters:
context- the request context- See Also:
saveState(Context),removeState(Context)
-
saveState
public void saveState(org.openidentityplatform.openam.click.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(Context),removeState(Context)
-
createRowList
protected List<Object> createRowList()
Create a new table row list. If adataProvideris 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 ingetRowList.- 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 CSSclassattribute to each row with a value of eitheroddoreven. You are free to add other CSS class attributes as illustrated in the example above.- Parameters:
attributes- the row attributesrow- the domain object currently being renderedrowIndex- 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 inrowIndex- 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.userenderPaginator(HtmlStringBuffer)instead, this method is provided to support backward compatibility older Click 1.4 customized tables. In these scenarios please overriderenderPaginator(HtmlStringBuffer)method to invokerenderTableBanner(HtmlStringBuffer)andrenderPagingControls(HtmlStringBuffer).Render the table banner detailing number of rows and number displayed.See the
/click-controls.propertiesfor the HTML templates:table-page-bannerandtable-page-banner-nolinks- Parameters:
buffer- the StringBuffer to render the paging controls to
-
renderPagingControls
protected void renderPagingControls(HtmlStringBuffer buffer)
Deprecated.userenderPaginator(HtmlStringBuffer)instead, this method is provided to support backward compatibility older Click 1.4 customized tables. In these scenarios please overriderenderPaginator(HtmlStringBuffer)method to invokerenderTableBanner(HtmlStringBuffer)andrenderPagingControls(HtmlStringBuffer).Render the table paging action link controls.See the
/click-controls.propertiesfor the HTML templates:table-page-linksandtable-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.
-
-