org.apache.wicket.extensions.markup.html.repeater.data.table
Class DataTable<T,S>

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.panel.Panel
                  extended by org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable<T,S>
Type Parameters:
T - The model object type
S - the type of the sorting parameter
All Implemented Interfaces:
Serializable, Iterable<Component>, IEventSink, IEventSource, IConverterLocator, IHeaderContributor, IPageable, IPageableItems, IRequestableComponent, org.apache.wicket.util.IHierarchical<Component>, org.apache.wicket.util.io.IClusterable
Direct Known Subclasses:
AjaxFallbackDefaultDataTable, DefaultDataTable

public class DataTable<T,S>
extends Panel
implements IPageableItems

A data table builds on data grid view to introduce toolbars. Toolbars can be used to display sortable column headers, paging information, filter controls, and other information.

Data table also provides its own markup for an html table so the user does not need to provide it himself. This makes it very simple to add a datatable to the markup, however, some flexibility.

Example

 <table wicket:id="datatable"></table>
 
And the related Java code: ( the first column will be sortable because its sort property is specified, the second column will not )
 List<IColumn<T>> columns = new ArrayList<IColumn<T>>();
 
 columns.add(new PropertyColumn(new Model<String>("First Name"), "name.first", "name.first"));
 columns.add(new PropertyColumn(new Model<String>("Last Name"), "name.last"));
 
 DataTable table = new DataTable("datatable", columns, new UserProvider(), 10);
 table.addBottomToolbar(new NavigationToolbar(table));
 table.addTopToolbar(new HeadersToolbar(table, null));
 add(table);
 

Author:
Igor Vaynberg (ivaynberg)
See Also:
DefaultDataTable, Serialized Form

Field Summary
 
Fields inherited from class org.apache.wicket.markup.html.panel.Panel
PANEL
 
Fields inherited from class org.apache.wicket.Component
ENABLE, FLAG_INITIALIZED, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
DataTable(String id, List<? extends IColumn<T,S>> columns, IDataProvider<T> dataProvider, long rowsPerPage)
          Constructor
  tag.
Method Summary
 void addBottomToolbar(AbstractToolbar toolbar)
          Adds a toolbar to the datatable that will be displayed after the data
 void addTopToolbar(AbstractToolbar toolbar)
          Adds a toolbar to the datatable that will be displayed before the data
 WebMarkupContainer getBody()
           
 org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.ToolbarsContainer getBottomToolbars()
           
 org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.Caption getCaption()
           
protected  IModel<String> getCaptionModel()
          Returns the model for table's caption.
 List<? extends IColumn<T,S>> getColumns()
           
 long getCurrentPage()
           
 IDataProvider<T> getDataProvider()
           
 long getItemCount()
           
 long getItemsPerPage()
           
 long getPageCount()
           
 long getRowCount()
           
 org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.ToolbarsContainer getTopToolbars()
           
protected  WebMarkupContainer newBodyContainer(String id)
          Create the MarkupContainer for the
protected  Item<IColumn<T,S>> newCellItem(String id, int index, IModel<IColumn<T,S>> model)
          Factory method for Item container that represents a cell in the underlying DataGridView
protected  Item<T> newRowItem(String id, int index, IModel<T> model)
          Factory method for Item container that represents a row in the underlying DataGridView
protected  void onDetach()
           
protected  void onPageChanged()
          Event listener for page-changed event
 void setCurrentPage(long page)
           
 DataTable<T,S> setItemReuseStrategy(IItemReuseStrategy strategy)
          Sets the item reuse strategy.
 void setItemsPerPage(long items)
          Sets the number of items to be displayed per page
 void setTableBodyCss(String cssStyle)
          Set the 'class' attribute for the tbody tag.
 
Methods inherited from class org.apache.wicket.markup.html.panel.Panel
newMarkupSourcingStrategy
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest, getWebResponse, getWebSession
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onRender, remove, remove, removeAll, renderAll, renderAssociatedMarkup, renderNext, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, configure, continueToOriginalDestination, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onAfterRender, onBeforeRender, onComponentTag, onConfigure, onEvent, onInitialize, onModelChanged, onModelChanging, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, visitParents, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataTable

public DataTable(String id,
                 List<? extends IColumn<T,S>> columns,
                 IDataProvider<T> dataProvider,
                 long rowsPerPage)
Constructor

Parameters:
id - component id
columns - list of IColumn objects
dataProvider - imodel for data provider
rowsPerPage - number of rows per page
Method Detail

getCaptionModel

protected IModel<String> getCaptionModel()
Returns the model for table's caption. The caption wont be rendered if the model has empty value.

Returns:
the model for table's caption

newBodyContainer

protected WebMarkupContainer newBodyContainer(String id)
Create the MarkupContainer for the tag. Users may subclass it to provide their own (modified) implementation.

Parameters:
id -
Returns:
A new markup container

setTableBodyCss

public final void setTableBodyCss(String cssStyle)
Set the 'class' attribute for the tbody tag.

Parameters:
cssStyle -

addBottomToolbar

public void addBottomToolbar(AbstractToolbar toolbar)
Adds a toolbar to the datatable that will be displayed after the data

Parameters:
toolbar - toolbar to be added
See Also:
AbstractToolbar

addTopToolbar

public void addTopToolbar(AbstractToolbar toolbar)
Adds a toolbar to the datatable that will be displayed before the data

Parameters:
toolbar - toolbar to be added
See Also:
AbstractToolbar

getTopToolbars

public final org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.ToolbarsContainer getTopToolbars()
Returns:
the container with the toolbars at the top

getBottomToolbars

public final org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.ToolbarsContainer getBottomToolbars()
Returns:
the container with the toolbars at the bottom

getBody

public final WebMarkupContainer getBody()
Returns:
the container used for the table body

getCaption

public final org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.Caption getCaption()
Returns:
the component used for the table caption

getDataProvider

public final IDataProvider<T> getDataProvider()
Returns:
dataprovider

getColumns

public final List<? extends IColumn<T,S>> getColumns()
Returns:
array of column objects this table displays

getCurrentPage

public final long getCurrentPage()
Specified by:
getCurrentPage in interface IPageable
See Also:
IPageable.getCurrentPage()

getPageCount

public final long getPageCount()
Specified by:
getPageCount in interface IPageable
See Also:
IPageable.getPageCount()

getRowCount

public final long getRowCount()
Returns:
total number of rows in this table

getItemsPerPage

public final long getItemsPerPage()
Specified by:
getItemsPerPage in interface IPageableItems
Returns:
number of rows per page

setCurrentPage

public final void setCurrentPage(long page)
Specified by:
setCurrentPage in interface IPageable
See Also:
IPageable.setCurrentPage(long)

setItemReuseStrategy

public final DataTable<T,S> setItemReuseStrategy(IItemReuseStrategy strategy)
Sets the item reuse strategy. This strategy controls the creation of Items.

Parameters:
strategy - item reuse strategy
Returns:
this for chaining
See Also:
RefreshingView.setItemReuseStrategy(IItemReuseStrategy), IItemReuseStrategy

setItemsPerPage

public void setItemsPerPage(long items)
Sets the number of items to be displayed per page

Specified by:
setItemsPerPage in interface IPageableItems
Parameters:
items - number of items to display per page

getItemCount

public long getItemCount()
Specified by:
getItemCount in interface IPageableItems
See Also:
IPageableItems.getItemCount()

newCellItem

protected Item<IColumn<T,S>> newCellItem(String id,
                                         int index,
                                         IModel<IColumn<T,S>> model)
Factory method for Item container that represents a cell in the underlying DataGridView

Parameters:
id - component id for the new data item
index - the index of the new data item
model - the model for the new data item
Returns:
DataItem created DataItem
See Also:
Item

newRowItem

protected Item<T> newRowItem(String id,
                             int index,
                             IModel<T> model)
Factory method for Item container that represents a row in the underlying DataGridView

Parameters:
id - component id for the new data item
index - the index of the new data item
model - the model for the new data item.
Returns:
DataItem created DataItem
See Also:
Item

onDetach

protected void onDetach()
Overrides:
onDetach in class Component
See Also:
Component.onDetach()

onPageChanged

protected void onPageChanged()
Event listener for page-changed event



Copyright © 2006-2013 Apache Software Foundation. All Rights Reserved.