All Implemented Interfaces:
IDynamicComponent, IExtendedTable, ITableRowStateHolder, Serializable, EventListener, ClientBehaviorHolder, NamingContainer, PartialStateHolder, StateHolder, TransientStateHolder, UniqueIdVendor, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder
Direct Known Subclasses:
AsyncTable, CategorizedTable, Chart, DataList, DataTree, SearchResultTable

public class DataTable extends HtmlDataTable implements IExtendedTable, ITableRowStateHolder, IDynamicComponent
See Also:
  • Field Details

    • content

      protected transient ITableContentProvider content

      The ITableContentProvider associated with this component, lazily instantiated if requested. This object is not part of the saved and restored state of the component.

    • saved

      protected Map<String,Object> saved

      This map contains SavedState instances for each descendant component, keyed by the client identifier of the descendant. Because descendant client identifiers will contain the rowIndex value of the parent, per-row state information is actually preserved.

    • sortKeys

      protected transient SortInfo sortKeys
      Temporary sort info with sort keys.
    • sortIds

      protected transient SortInfo sortIds
      Temporary sort info with sort ids.
    • templateRowId

      protected String templateRowId
      Pseudo-id of current row to create, or null to use normal row index.
    • rowsToCreate

      protected String[] rowsToCreate
      (unqualified, client) ids of rows to create.
    • rowsToMove

      protected IExtendedTable.RowMovement[] rowsToMove
      (unqualified, client) ids by new indicies of rows to move.
    • rowsToDelete

      protected String[] rowsToDelete
      (unqualified, client) ids of rows to delete.
    • rowsToUpdate

      protected String[] rowsToUpdate
      (unqualified, client) ids of rows to update.
    • NO_LAZY_INDEX

      protected static final int NO_LAZY_INDEX
      Constant to indicate that there is no lazy row index to set.
      See Also:
    • lazyRowIndex

      protected transient int lazyRowIndex
      Row Index to use when the content provider becomes available
    • skipRowIndexLookup

      protected transient boolean skipRowIndexLookup
      To workaround issues creating the clientId of table rows after upgrade to JSF 2.x
    • TYPE

      public static final String TYPE
      New CAF specific renderer-type
      See Also:
  • Constructor Details

    • DataTable

      public DataTable()
  • Method Details

    • getFirst

      public int getFirst()

      Return the zero-relative row number of the first row to be displayed.

      Overrides:
      getFirst in class UIData
    • setFirst

      public void setFirst(int first)

      Set the zero-relative row number of the first row to be displayed.

      Overrides:
      setFirst in class UIData
      Parameters:
      first - New first row number
      Throws:
      IllegalArgumentException - if first is negative
    • isRowAvailable

      public boolean isRowAvailable()

      Return a flag indicating whether there is rowData available at the current rowIndex. If no wrappedData is available, return false.

      Overrides:
      isRowAvailable in class UIData
      Throws:
      FacesException - if an error occurs getting the row availability
    • getRowCount

      public int getRowCount()

      Return the number of rows in the underlying data model. If the number of available rows is unknown, return -1.

      Overrides:
      getRowCount in class UIData
      Throws:
      FacesException - if an error occurs getting the row count
    • getRowData

      public Object getRowData()

      Return the data object representing the data for the currently selected row index, if any.

      Overrides:
      getRowData in class UIData
      Throws:
      FacesException - if an error occurs getting the row data
      IllegalArgumentException - if now row data is available at the currently specified row index
    • getRowIndex

      public int getRowIndex()

      Return the zero-relative index of the currently selected row. If were not currently positioned on a row, return -1. This property is not enabled for value binding expressions.

      Overrides:
      getRowIndex in class UIData
      Throws:
      FacesException - if an error occurs getting the row index
    • setLazyRowIndex

      public void setLazyRowIndex(int rowIndex)
      If the content provider has not been created yet, delay setting the row index until it is available.
      Parameters:
      rowIndex - the row index
    • setRowIndex

      public void setRowIndex(int rowIndex)

      Set the zero relative index of the current row, or -1 to indicate that no row is currently selected, by implementing the following algorithm. It is possible to set the row index at a value for which the underlying data collection does not contain any row data. Therefore, callers may use the isRowAvailable() method to detect whether row data will be available for use by the getRowData() method.

      • Save current state information for all descendant components (as described below).
      • Store the new row index, and pass it on to the DataModel associated with this UIData instance.
      • If the new rowIndex value is -1:
        • If the var property is not null, remove the corresponding request scope attribute (if any).
        • Reset the state information for all descendant components (as described below).
      • If the new rowIndex value is not -1:
        • If the var property is not null, call getRowData() and expose the resulting data object as a request scope attribute whose key is the var property value.
        • Reset the state information for all descendant components (as described below).

      To save current state information for all descendant components, UIData must maintain per-row information for each descendant as follows:

      • If the descendant is an instance of EditableValueHolder, save the state of its localValue property.
      • If the descendant is an instance of EditableValueHolder, save the state of the localValueSet property.
      • If the descendant is an instance of EditableValueHolder, save the state of the valid property.
      • If the descendant is an instance of EditableValueHolder, save the state of the submittedValue property.

      To restore current state information for all descendant components, UIData must reference its previously stored information for the current rowIndex and call setters for each descendant as follows:

      • If the descendant is an instance of EditableValueHolder, restore the value property.
      • If the descendant is an instance of EditableValueHolder, restore the state of the localValueSet property.
      • If the descendant is an instance of EditableValueHolder, restore the state of the valid property.
      • If the descendant is an instance of EditableValueHolder, restore the state of the submittedValue property.
      Overrides:
      setRowIndex in class UIData
      Parameters:
      rowIndex - The new row index value, or -1 for no associated row
      Throws:
      FacesException - if an error occurs setting the row index
      IllegalArgumentException - if rowIndex is less than -1
    • getRows

      public int getRows()

      Return the number of rows to be displayed, or zero for all remaining rows in the table. The default value of this property is zero.

      Overrides:
      getRows in class UIData
    • setRows

      public void setRows(int rows)

      Set the number of rows to be displayed, or zero for all remaining rows in the table.

      Overrides:
      setRows in class UIData
      Parameters:
      rows - New number of rows
      Throws:
      IllegalArgumentException - if rows is negative
    • restoreState

      public void restoreState(FacesContext context, Object state)
      Specified by:
      restoreState in interface StateHolder
      Overrides:
      restoreState in class UIData
    • setValue

      public void setValue(Object value)

      Set the value of the UIData. This value must either be be of type DataModel, or a type that can be adapted into a DataModel.

      Overrides:
      setValue in class UIData
      Parameters:
      value - the new value
    • setValueBinding

      @Deprecated public void setValueBinding(String name, ValueBinding binding)

      Set the ValueBinding used to calculate the value for the specified attribute or property name, if any. In addition, if a ValueBinding is set for the value property, remove any synthesized DataModel for the data previously bound to this component.

      Overrides:
      setValueBinding in class UIData
      Parameters:
      name - Name of the attribute or property for which to set a ValueBinding
      binding - The ValueBinding to set, or null to remove any currently set ValueBinding
      Throws:
      IllegalArgumentException - if name is one of id, parent, var, or rowIndex
      NullPointerException - if name is null
    • setValueExpression

      public void setValueExpression(String name, ValueExpression binding)
      Overrides:
      setValueExpression in class UIData
    • getClientId

      public String getClientId(FacesContext context)

      Return a client identifier for this component that includes the current value of the rowIndex property, if it is not set to -1. This implies that multiple calls to getClientId() may return different results, but ensures that child components can themselves generate row-specific client identifiers (since UIData is a NamingContainer).

      Overrides:
      getClientId in class UIData
      Throws:
      NullPointerException - if context is null
    • toClientRowId

      protected String toClientRowId(String id)
      Add client row id prefix.
    • fromClientRowId

      protected String fromClientRowId(String id)
      Remove client row id prefix.
    • queueEvent

      public void queueEvent(FacesEvent event)

      Override the default UIComponentBase.queueEvent(javax.faces.event.FacesEvent) processing to wrap any queued events in a wrapper so that we can reset the current row index in broadcast().

      Overrides:
      queueEvent in class UIData
      Parameters:
      event - FacesEvent to be queued
      Throws:
      IllegalStateException - if this component is not a descendant of a UIViewRoot
      NullPointerException - if event is null
    • broadcast

      public void broadcast(FacesEvent event) throws AbortProcessingException

      Override the default UIComponentBase.broadcast(javax.faces.event.FacesEvent) processing to unwrap any wrapped FacesEvent and reset the current row index, before the event is actually broadcast. For events that we did not wrap (in queueEvent()), default processing will occur.

      Overrides:
      broadcast in class UIData
      Parameters:
      event - The FacesEvent to be broadcast
      Throws:
      AbortProcessingException - Signal the JavaServer Faces implementation that no further processing on the current event should be performed
      IllegalArgumentException - if the implementation class of this FacesEvent is not supported by this component
      NullPointerException - if event is null
    • encodeBegin

      public void encodeBegin(FacesContext context) throws IOException

      In addition to the default behavior, ensure that any saved per-row state for our child input components is discarded unless it is needed to rerender the current page with errors.

      Overrides:
      encodeBegin in class UIData
      Parameters:
      context - FacesContext for the current request
      Throws:
      IOException - if an input/output error occurs while rendering
      NullPointerException - if context is null
    • prepareForEncode

      protected void prepareForEncode(FacesContext context)
      Sub-classes may override to prepare their controls for encoding.
      Parameters:
      context - FacesContext for the current request
    • processDecodes

      public void processDecodes(FacesContext context)

      Override the default UIComponentBase.processDecodes(javax.faces.context.FacesContext) processing to perform the following steps.

      • If the rendered property of this UIComponent is false, skip further processing.
      • Set the current rowIndex to -1.
      • Call the processDecodes() method of all facets of this UIData, in the order determined by a call to getFacets().keySet().iterator().
      • Call the processDecodes() method of all facets of the UIColumn children of this UIData.
      • Iterate over the set of rows that were included when this component was rendered (i.e. those defined by the first and rows properties), performing the following processing for each row:
        • Set the current rowIndex to the appropriate value for this row.
        • If isRowAvailable() returns true, iterate over the children components of each UIColumn child of this UIData component, calling the processDecodes() method for each such child.
      • Set the current rowIndex to -1.
      • Call the decode() method of this component.
      • If a RuntimeException is thrown during decode processing, call FacesContext.renderResponse() and re-throw the exception.
      Overrides:
      processDecodes in class UIData
      Parameters:
      context - FacesContext for the current request
      Throws:
      NullPointerException - if context is null
    • processValidators

      public void processValidators(FacesContext context)

      Override the default UIComponentBase.processValidators(javax.faces.context.FacesContext) processing to perform the following steps.

      • If the rendered property of this UIComponent is false, skip further processing.
      • Set the current rowIndex to -1.
      • Call the processValidators() method of all facets of this UIData, in the order determined by a call to getFacets().keySet().iterator().
      • Call the processValidators() method of all facets of the UIColumn children of this UIData.
      • Iterate over the set of rows that were included when this component was rendered (i.e. those defined by the first and rows properties), performing the following processing for each row:
        • Set the current rowIndex to the appropriate value for this row.
        • If isRowAvailable() returns true, iterate over the children components of each UIColumn child of this UIData component, calling the processValidators() method for each such child.
      • Set the current rowIndex to -1.
      Overrides:
      processValidators in class UIData
      Parameters:
      context - FacesContext for the current request
      Throws:
      NullPointerException - if context is null
    • processUpdates

      public void processUpdates(FacesContext context)

      Override the default UIComponentBase.processUpdates(javax.faces.context.FacesContext) processing to perform the following steps.

      • If the rendered property of this UIComponent is false, skip further processing.
      • Set the current rowIndex to -1.
      • Call the processUpdates() method of all facets of this UIData, in the order determined by a call to getFacets().keySet().iterator().
      • Call the processUpdates() method of all facets of the UIColumn children of this UIData.
      • Iterate over the set of rows that were included when this component was rendered (i.e. those defined by the first and rows properties), performing the following processing for each row:
        • Set the current rowIndex to the appropriate value for this row.
        • If isRowAvailable() returns true, iterate over the children components of each UIColumn child of this UIData component, calling the processUpdates() method for each such child.
      • Set the current rowIndex to -1.
      Overrides:
      processUpdates in class UIData
      Parameters:
      context - FacesContext for the current request
      Throws:
      NullPointerException - if context is null
    • getTableRowState

      public Object getTableRowState()
      Gets this control's per-row state.
      Specified by:
      getTableRowState in interface ITableRowStateHolder
    • setTableRowState

      public void setTableRowState(Object o)
      Sets this control's per-row state.
      Specified by:
      setTableRowState in interface ITableRowStateHolder
    • getSortInfo

      public ISortInfo getSortInfo(boolean keysNotColumnIds)
      Description copied from interface: IExtendedTable
      Current sort info. Never null.
      Specified by:
      getSortInfo in interface IExtendedTable
      Parameters:
      keysNotColumnIds - True to report keys using column "sort" property, false to report keys using column ids.
    • getRowId

      public String getRowId()
      Description copied from interface: IExtendedTable
      Get unique identifier for the current row. If no current row, returns null.
      Specified by:
      getRowId in interface IExtendedTable
    • setRowById

      public void setRowById(String id)
      Description copied from interface: IExtendedTable
      Set current row by id. If id doesn't identify a row, makes no row current (equivalent to setRowIndex(-1)).
      Specified by:
      setRowById in interface IExtendedTable
    • getCanTemplateRow

      public boolean getCanTemplateRow()
      Description copied from interface: IExtendedTable
      True if provider can be put into template row state.
      Specified by:
      getCanTemplateRow in interface IExtendedTable
      See Also:
    • isTemplateRow

      public boolean isTemplateRow()
      Description copied from interface: IExtendedTable
      Is provider in state where it returns properties for template pseudo-row. In this state, row index is -1 and row id is null. Setting the row index or id to any value removes provider from this state.
      Specified by:
      isTemplateRow in interface IExtendedTable
    • setTemplateRow

      public void setTemplateRow()
      Description copied from interface: IExtendedTable
      Sets provider to state where it returns properties for template pseudo-row. In this state, row index is -1 and row id is null. Setting the row index or id to any value removes provider from this state.
      Specified by:
      setTemplateRow in interface IExtendedTable
    • updateRowsToCreate

      protected void updateRowsToCreate()
      Update rowsToCreate, rowsToUpdate, and indiciesToCreate by mapping original row ids to already created row ids.
    • getRowsToCreate

      public String[] getRowsToCreate()
      Description copied from interface: IExtendedTable
      List of pseudo-ids (used for client-id in place of row index) of new rows to create, or null.
      Specified by:
      getRowsToCreate in interface IExtendedTable
    • setRowsToCreate

      public void setRowsToCreate(String[] create)
      Description copied from interface: IExtendedTable
      List of pseudo-ids (used for client-id in place of row index) of new rows to create, or null.
      Specified by:
      setRowsToCreate in interface IExtendedTable
    • getRowsToMove

      public IExtendedTable.RowMovement[] getRowsToMove()
      Description copied from interface: IExtendedTable
      List of ids to move by list of to move in front of. Null or empty string ("") signals move to end.
      Specified by:
      getRowsToMove in interface IExtendedTable
    • setRowsToMove

      public void setRowsToMove(IExtendedTable.RowMovement[] move)
      Description copied from interface: IExtendedTable
      List of ids to move by list of to move in front of. Null or empty string ("") signals move to end.
      Specified by:
      setRowsToMove in interface IExtendedTable
    • getRowsToDelete

      public String[] getRowsToDelete()
      Description copied from interface: IExtendedTable
      List of ids of rows to delete, or null.
      Specified by:
      getRowsToDelete in interface IExtendedTable
    • setRowsToDelete

      public void setRowsToDelete(String[] delete)
      Description copied from interface: IExtendedTable
      List of ids of rows to delete, or null.
      Specified by:
      setRowsToDelete in interface IExtendedTable
    • getRowsToUpdate

      public String[] getRowsToUpdate()
      Description copied from interface: IExtendedTable
      List of ids of rows to update, or null.
      Specified by:
      getRowsToUpdate in interface IExtendedTable
    • setRowsToUpdate

      public void setRowsToUpdate(String[] update)
      Description copied from interface: IExtendedTable
      List of ids of rows to update, or null.
      Specified by:
      setRowsToUpdate in interface IExtendedTable
    • convertOriginalToCreatedRowIds

      public Collection<String> convertOriginalToCreatedRowIds(Collection<String> ids)
      Description copied from interface: IExtendedTable
      Converts client-generated ids to the actual row ids (ie from "__new1234" to "myRowOne").
      Specified by:
      convertOriginalToCreatedRowIds in interface IExtendedTable
    • convertCreatedToOriginalRowIds

      public Collection<String> convertCreatedToOriginalRowIds(Collection<String> ids)
      Description copied from interface: IExtendedTable
      Converts actual row ids to the original client-generated ids (ie from "myRowOne" to "__new1234").
      Specified by:
      convertCreatedToOriginalRowIds in interface IExtendedTable
    • getFilter

      public String getFilter()
      Description copied from interface: IExtendedTable
      Filter expression. Only rows matched by this filter should be exposed. Null or empty ("") signals expose the default set of rows.
      Specified by:
      getFilter in interface IExtendedTable
    • setFilter

      public void setFilter(String filter)
      Description copied from interface: IExtendedTable
      Filter expression. Only rows matched by this filter should be exposed. Null or empty ("") signals expose the default set of rows.
      Specified by:
      setFilter in interface IExtendedTable
    • resetRowCaches

      public void resetRowCaches()
      Description copied from interface: IExtendedTable
      Clear out any cached information about the rows. Call if the content provider has changed.
      Specified by:
      resetRowCaches in interface IExtendedTable
    • iterate

      protected void iterate(FacesContext context, PhaseId phaseId)

      Perform the appropriate phase-specific processing and per-row iteration for the specified phase, as follows:

      • Set the rowIndex property to -1, and process the facets of this UIData component exactly once.
      • Set the rowIndex property to -1, and process the facets of the UIColumn children of this UIData component exactly once.
      • Iterate over the relevant rows, based on the first and row properties, and process the children of the UIColumn children of this UIData component once per row.
      Parameters:
      context - FacesContext for the current request
      phaseId - PhaseId of the phase we are currently running
    • processColumnChild

      protected void processColumnChild(FacesContext context, UIComponent component, PhaseId phaseId)
      Process column child, as appropriate for specified phase.
    • setTemplateRowId

      protected void setTemplateRowId(String id)
      Set pseudo-id for row to be created, making it the current row.
    • keepSaved

      protected boolean keepSaved(FacesContext context)

      Return true if we need to keep the saved per-child state information. This will be the case if any of the following are true:

      • any of the saved state corresponds to components that have messages that must be displayed
      • this UIData instance is nested inside of another UIData instance
      Parameters:
      context - FacesContext for the current request
    • isNestedWithinUIData

      protected boolean isNestedWithinUIData()
    • restoreDescendantState

      protected void restoreDescendantState()

      Restore state information for all descendant components, as described for setRowIndex().

    • clearDescendantState

      protected void clearDescendantState(UIComponent component, FacesContext context)
      Clears out the cached clientId for descendant controls when the current row is invalid.
    • restoreDescendantState

      protected void restoreDescendantState(UIComponent component, FacesContext context)

      Restore state information for the specified component and its descendants.

      Parameters:
      component - Component for which to restore state information
      context - FacesContext for the current request
    • saveDescendantState

      protected void saveDescendantState()

      Save state information for all descendant components, as described for setRowIndex().

    • saveDescendantState

      protected void saveDescendantState(UIComponent component, FacesContext context)

      Save state information for the specified component and its descendants.

      Parameters:
      component - Component for which to save state information
      context - FacesContext for the current request
    • getContentProvider

      public ITableContentProvider getContentProvider()
      Lazily gets table-content-provider, wrapping raw value if necessary.
      Specified by:
      getContentProvider in interface IExtendedTable
    • getContentProvider

      protected ITableContentProvider getContentProvider(boolean applyLazyRowIndex)
      Lazily gets table-content-provider, wrapping raw value if necessary.
      Parameters:
      applyLazyRowIndex - Apply the lazy row index if it is available.
    • clearContent

      protected void clearContent()
      Clear cached content.
    • resetContent

      public void resetContent()
    • sort

      protected void sort()
      Sorts the content provider according to the state of the table's extended columns.
    • filter

      protected void filter()
      Filters the content provider according to the state of the table's filter property.
    • getExportSettings

      protected UIComponent getExportSettings()
      Control which handles table's export settings.
    • populateInitialComponents

      public void populateInitialComponents()
      Description copied from interface: IDynamicComponent
      Perform the initial programmatic manipulation of the component tree.
      Specified by:
      populateInitialComponents in interface IDynamicComponent