org.rhq.enterprise.gui.common.paging
Class PagedListDataModel<T>

java.lang.Object
  extended by javax.faces.model.DataModel
      extended by org.rhq.enterprise.gui.common.paging.PagedListDataModel<T>
Type Parameters:
T - the data type to be stored in the dataset
Direct Known Subclasses:
ListAvailabilityHistoryUIBean.ListAvailabilityHistoryDataModel, ListChildResourcesUIBean.ListChildResourcesDataModel, ListContainingGroupsUIBean.ListContainingGroupsDataModel, ResourceGroupMetricsTableUIBean.ResourceGroupHealthSummaryDataModel, ResourceNameDisambiguatingPagedListDataModel

public abstract class PagedListDataModel<T>
extends javax.faces.model.DataModel

A special type of JSF DataModel to allow a table and datascroller to page through a large set of data without having to hold the entire set of data in memory at once.

Any time a managed bean wants to avoid holding an entire dataset, the managed bean should declare an inner class which extends this class and implements the fetchData method. This method is called as needed when the table requires data that isn't available in the current data page held by this object.

This does require the managed bean (and in general the business method that the managed bean uses) to provide the data wrapped in a PageList object that provides info on the full size of the dataset.

Adapted from - http://wiki.apache.org/myfaces/WorkingWithLargeTables

Author:
Joseph Marques

Constructor Summary
PagedListDataModel(PageControlView view, String beanName)
          Create a datamodel that pages through the data showing the specified number of rows on each page.
 
Method Summary
abstract  org.rhq.core.domain.util.PageList<T> fetchPage(org.rhq.core.domain.util.PageControl pc)
          Method which must be implemented in cooperation with the managed bean class to fetch data on demand.
 org.rhq.core.domain.util.PageList<T> getDataPage(org.rhq.core.domain.util.PageControl pc)
           
 org.rhq.core.domain.util.PageControl getDefaultPageControl()
           
 org.rhq.core.domain.util.PageControl getPageControl()
           
 PageControlView getPageControlView()
           
 int getRowCount()
          Return the total number of rows of data available (not just the number of rows in the current page!).
 Object getRowData()
          Return the object corresponding to the current getRowIndex().
 int getRowIndex()
           
 Object getWrappedData()
           
 boolean isRowAvailable()
          Return true if the getRowIndex() value is currently set to a value that matches some element in the dataset.
 void setPageControl(org.rhq.core.domain.util.PageControl pageControl)
           
 void setRowIndex(int index)
          Specify what the "current row" within the dataset is.
 void setWrappedData(Object o)
          Not used in this class; data is fetched via a callback to the getDataPage(PageControl) method rather than by explicitly assigning a list.
 
Methods inherited from class javax.faces.model.DataModel
addDataModelListener, getDataModelListeners, removeDataModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PagedListDataModel

public PagedListDataModel(PageControlView view,
                          String beanName)
Create a datamodel that pages through the data showing the specified number of rows on each page.

Parameters:
pageSize - the total number of pages in the full dataset
Method Detail

setWrappedData

public void setWrappedData(Object o)
Not used in this class; data is fetched via a callback to the getDataPage(PageControl) method rather than by explicitly assigning a list.

Specified by:
setWrappedData in class javax.faces.model.DataModel
Parameters:
o - unused
Throws:
UnsupportedOperationException - thrown when this method is called

getRowIndex

public int getRowIndex()
Specified by:
getRowIndex in class javax.faces.model.DataModel

setRowIndex

public void setRowIndex(int index)
Specify what the "current row" within the dataset is. Note that the UIData component will repeatedly call this method followed by getRowData to obtain the objects to render in the table.

Specified by:
setRowIndex in class javax.faces.model.DataModel
Parameters:
index - current row index, indexes start at 0

getRowCount

public int getRowCount()
Return the total number of rows of data available (not just the number of rows in the current page!).

Specified by:
getRowCount in class javax.faces.model.DataModel
Returns:
number of rows in the full dataset

getRowData

public Object getRowData()
Return the object corresponding to the current getRowIndex(). If the PageList object currently cached doesn't include that index then getDataPage(PageControl) is called to retrieve the appropriate page.

Specified by:
getRowData in class javax.faces.model.DataModel
Returns:
the row data that corresponds to getRowIndex()
Throws:
IllegalArgumentException - if the getRowIndex() is outside the range of the dataset size

getWrappedData

public Object getWrappedData()
Specified by:
getWrappedData in class javax.faces.model.DataModel

isRowAvailable

public boolean isRowAvailable()
Return true if the getRowIndex() value is currently set to a value that matches some element in the dataset. Note that it may match a row that is not in the currently cached PageList; if so then when getRowData() is called the required PageList will be fetched by calling getDataPage(PageControl).

Specified by:
isRowAvailable in class javax.faces.model.DataModel
Returns:
true if the row is available

getPageControl

public org.rhq.core.domain.util.PageControl getPageControl()

getDefaultPageControl

public org.rhq.core.domain.util.PageControl getDefaultPageControl()

setPageControl

public void setPageControl(org.rhq.core.domain.util.PageControl pageControl)

getDataPage

public org.rhq.core.domain.util.PageList<T> getDataPage(org.rhq.core.domain.util.PageControl pc)

fetchPage

public abstract org.rhq.core.domain.util.PageList<T> fetchPage(org.rhq.core.domain.util.PageControl pc)
Method which must be implemented in cooperation with the managed bean class to fetch data on demand.

Parameters:
pc - information such as the first row of data to be fetched, the number of rows of data to be fetched and sorting data
Returns:
the data page with the rows in memory

getPageControlView

public PageControlView getPageControlView()


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.