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

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>
Type Parameters:
T - The model object type
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Component>, IEventSink, IEventSource, IClusterable, IConverterLocator, IHeaderContributor, IPageable, IPageableItems, IRequestableComponent, IHierarchical<Component>
Direct Known Subclasses:
AjaxFallbackDefaultDataTable, DefaultDataTable

public class DataTable<T>
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(java.lang.String id, java.util.List<IColumn<T>> columns, IDataProvider<T> dataProvider, int 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
protected  IModel<java.lang.String> getCaptionModel()
          Returns the model for table's caption.
 java.util.List<IColumn<T>> getColumns()
           
 int getCurrentPage()
           
 IDataProvider<T> getDataProvider()
           
 int getItemCount()
          Gets the total number of items this object has.
 int getItemsPerPage()
          maximum number of visible items per page
 int getPageCount()
          Gets the total number of pages this pageable object has.
 int getRowCount()
           
protected  WebMarkupContainer newBodyContainer(java.lang.String id)
          Create the MarkupContainer for the
protected  Item<IColumn<T>> newCellItem(java.lang.String id, int index, IModel<IColumn<T>> model)
          Factory method for Item container that represents a cell in the underlying DataGridView
protected  Item<T> newRowItem(java.lang.String id, int index, IModel<T> model)
          Factory method for Item container that represents a row in the underlying DataGridView
protected  void onDetach()
          Called to allow a component to detach resources after use.
protected  void onPageChanged()
          Event listener for page-changed event
 void setCurrentPage(int page)
          Sets the a page that should be rendered (page number is zero-based)
 DataTable<T> setItemReuseStrategy(IItemReuseStrategy strategy)
          Sets the item reuse strategy.
 void setItemsPerPage(int items)
          Sets the number of items to be displayed per page
 void setTableBodyCss(java.lang.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
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, hasAssociatedMarkup, internalAdd, internalInitialize, iterator, iterator, onAfterRenderChildren, onComponentTagBody, onMarkupAttached, 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, getFeedbackMessage, 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, locateMarkupStream, 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, warn, wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataTable

public DataTable(java.lang.String id,
                 java.util.List<IColumn<T>> columns,
                 IDataProvider<T> dataProvider,
                 int 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<java.lang.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(java.lang.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(java.lang.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

getDataProvider

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

getColumns

public final java.util.List<IColumn<T>> getColumns()
Returns:
array of column objects this table displays

getCurrentPage

public final int getCurrentPage()
Specified by:
getCurrentPage in interface IPageable
Returns:
The current page that is or will be rendered (page number is zero-based)
See Also:
IPageable.getCurrentPage()

getPageCount

public final int getPageCount()
Description copied from interface: IPageable
Gets the total number of pages this pageable object has.

Specified by:
getPageCount in interface IPageable
Returns:
The total number of pages this pageable object has
See Also:
IPageable.getPageCount()

getRowCount

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

getItemsPerPage

public final int getItemsPerPage()
Description copied from interface: IPageableItems
maximum number of visible items per page

Specified by:
getItemsPerPage in interface IPageableItems
Returns:
number of rows per page

setCurrentPage

public final void setCurrentPage(int page)
Description copied from interface: IPageable
Sets the a page that should be rendered (page number is zero-based)

Specified by:
setCurrentPage in interface IPageable
Parameters:
page - The page that should be rendered.
See Also:
IPageable.setCurrentPage(int)

setItemReuseStrategy

public final DataTable<T> 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(int items)
Sets the number of items to be displayed per page

Parameters:
items - number of items to display per page

getItemCount

public int getItemCount()
Description copied from interface: IPageableItems
Gets the total number of items this object has.

Specified by:
getItemCount in interface IPageableItems
Returns:
The total number of items this object has.
See Also:
IPageableItems.getItemCount()

newCellItem

protected Item<IColumn<T>> newCellItem(java.lang.String id,
                                       int index,
                                       IModel<IColumn<T>> 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(java.lang.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()
Description copied from class: Component
Called to allow a component to detach resources after use. Overrides of this method MUST call the super implementation, the most logical place to do this is the last line of the override method.

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

onPageChanged

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



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