javax.faces.component
Class UIData

java.lang.Object
  |
  +--javax.faces.component.UIComponent
        |
        +--javax.faces.component.UIComponentBase
              |
              +--javax.faces.component.UIData
All Implemented Interfaces:
NamingContainer, StateHolder
Direct Known Subclasses:
HtmlDataTable

public class UIData
extends UIComponentBase
implements NamingContainer

UIData is a UIComponent that supports data binding to a collection of data objects represented by a DataModel instance, which is the current value of this component itself (typically established via a ValueBinding). During iterative processing over the rows of data in the data model, the object for the current row is exposed as a request attribute under the key specified by the var property.

Only children of type UIColumn should be processed by renderers associated with this component.

By default, the rendererType property is set to javax.faces.Table. This value can be changed by calling the setRendererType() method.


Field Summary
static java.lang.String COMPONENT_FAMILY
          The standard component family for this component.
static java.lang.String COMPONENT_TYPE
          The standard component type for this component.
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
UIData()
          Create a new UIData instance with default property values.
 
Method Summary
 void broadcast(javax.faces.event.FacesEvent event)
          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.
 void encodeBegin(javax.faces.context.FacesContext context)
          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.
 java.lang.String getClientId(javax.faces.context.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.
 java.lang.String getFamily()
          Return the identifier of the component family to which this component belongs.
 int getFirst()
          Return the zero-relative row number of the first row to be displayed.
 javax.faces.component.UIComponent getFooter()
          Return the footer facet of this component (if any).
 javax.faces.component.UIComponent getHeader()
          Return the header facet of this component (if any).
 int getRowCount()
          Return the number of rows in the underlying data model.
 java.lang.Object getRowData()
          Return the data object representing the data for the currently selected row index, if any.
 int getRowIndex()
          Return the zero-relative index of the currently selected row.
 int getRows()
          Return the number of rows to be displayed, or zero for all remaining rows in the table.
 java.lang.Object getValue()
          Return the value of the UIData.
 java.lang.String getVar()
          Return the request-scope attribute under which the data object for the current row will be exposed when iterating.
 boolean isRowAvailable()
          Return a flag indicating whether there is rowData available at the current rowIndex.
 void processDecodes(javax.faces.context.FacesContext context)
          Override the default UIComponentBase.processDecodes(javax.faces.context.FacesContext) processing to perform the following steps.
 void processUpdates(javax.faces.context.FacesContext context)
          Override the default UIComponentBase.processUpdates(javax.faces.context.FacesContext) processing to perform the following steps.
 void processValidators(javax.faces.context.FacesContext context)
          Override the default UIComponentBase.processValidators(javax.faces.context.FacesContext) processing to perform the following steps.
 void queueEvent(javax.faces.event.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().
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
           Perform any processing required to restore the state from the entries in the state Object.
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           Gets the state of the instance as a Serializable Object.
 void setFirst(int first)
          Set the zero-relative row number of the first row to be displayed.
 void setFooter(javax.faces.component.UIComponent footer)
          Set the footer facet of this component.
 void setHeader(javax.faces.component.UIComponent header)
          Set the header facet of this component.
 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.
 void setRows(int rows)
          Set the number of rows to be displayed, or zero for all remaining rows in the table.
 void setValue(java.lang.Object value)
          Set the value of the UIData.
 void setValueBinding(java.lang.String name, javax.faces.el.ValueBinding binding)
          Set the ValueBinding used to calculate the value for the specified attribute or property name, if any.
 void setVar(java.lang.String var)
          Set the request-scope attribute under which the data object for the current row wil be exposed when iterating.
 
Methods inherited from class javax.faces.component.UIComponentBase
addFacesListener, decode, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getFacesContext, getFacesListeners, getFacet, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, isRendered, isTransient, processRestoreState, processSaveState, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_TYPE

public static final java.lang.String COMPONENT_TYPE

The standard component type for this component.

See Also:
Constant Field Values

COMPONENT_FAMILY

public static final java.lang.String COMPONENT_FAMILY

The standard component family for this component.

See Also:
Constant Field Values
Constructor Detail

UIData

public UIData()

Create a new UIData instance with default property values.

Method Detail

getFamily

public java.lang.String getFamily()
Description copied from class: UIComponent

Return the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the rendererType property, may be used to select the appropriate Renderer for this component instance.

Specified by:
getFamily in class UIComponent

getFirst

public int getFirst()

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


setFirst

public void setFirst(int first)

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

Parameters:
first - New first row number
Throws:
java.lang.IllegalArgumentException - if first is negative

getFooter

public javax.faces.component.UIComponent getFooter()

Return the footer facet of this component (if any). A convenience method for getFacet("footer").


setFooter

public void setFooter(javax.faces.component.UIComponent footer)

Set the footer facet of this component. A convenience method for getFacets().put("footer", footer).

Parameters:
footer - the new footer facet
Throws:
java.lang.NullPointerException - if footer is null

getHeader

public javax.faces.component.UIComponent getHeader()

Return the header facet of this component (if any). A convenience method for getFacet("header").


setHeader

public void setHeader(javax.faces.component.UIComponent header)

Set the header facet of this component. A convenience method for getFacets().put("header", header).

Parameters:
header - the new header facet
Throws:
java.lang.NullPointerException - if header is null

isRowAvailable

public boolean isRowAvailable()

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

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.

Throws:
FacesException - if an error occurs getting the row count

getRowData

public java.lang.Object getRowData()

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

Throws:
FacesException - if an error occurs getting the row data
java.lang.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 we are not currently positioned on a row, return -1. This property is not enabled for value binding expressions.

Throws:
FacesException - if an error occurs getting 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.

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

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:

Parameters:
rowIndex - The new row index value, or -1 for no associated row
Throws:
FacesException - if an error occurs setting the row index
java.lang.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.


setRows

public void setRows(int rows)

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

Parameters:
rows - New number of rows
Throws:
java.lang.IllegalArgumentException - if rows is negative

getVar

public java.lang.String getVar()

Return the request-scope attribute under which the data object for the current row will be exposed when iterating. This property is not enabled for value binding expressions.


setVar

public void setVar(java.lang.String var)

Set the request-scope attribute under which the data object for the current row wil be exposed when iterating.

Parameters:
var - The new request-scope attribute name

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext context)
Description copied from interface: StateHolder

Gets the state of the instance as a Serializable Object.

If the class that implements this interface has references to instances that implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the StateHolder.saveState(javax.faces.context.FacesContext) method on all those instances as well. This method must not save the state of children and facets. That is done via the StateManager

This method must not alter the state of the implementing object. In other words, after executing this code:

 Object state = component.saveState(facesContext);
 

component should be the same as before executing it.

The return from this method must be Serializable

Specified by:
saveState in interface StateHolder
Overrides:
saveState in class UIComponentBase

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.Object state)
Description copied from interface: StateHolder

Perform any processing required to restore the state from the entries in the state Object.

If the class that implements this interface has references to instances that also implement StateHolder (such as a UIComponent with event handlers, validators, etc.) this method must call the StateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object) method on all those instances as well.

Specified by:
restoreState in interface StateHolder
Overrides:
restoreState in class UIComponentBase

getValue

public java.lang.Object getValue()

Return the value of the UIData. This value must either be be of type DataModel, or a type that can be adapted into a DataModel. UIData will automatically adapt the following types:

All other types will be adapted using the ScalarDataModel class, which will treat the object as a single row of data.


setValue

public void setValue(java.lang.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.

Parameters:
value - the new value

setValueBinding

public void setValueBinding(java.lang.String name,
                            javax.faces.el.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 UIComponentBase
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:
java.lang.IllegalArgumentException - if name is one of id, parent, var, or rowIndex
java.lang.NullPointerException - if name is null

getClientId

public java.lang.String getClientId(javax.faces.context.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 UIComponentBase
Throws:
java.lang.NullPointerException - if context is null

queueEvent

public void queueEvent(javax.faces.event.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 UIComponentBase
Parameters:
event - FacesEvent to be queued
Throws:
java.lang.IllegalStateException - if this component is not a descendant of a UIViewRoot
java.lang.NullPointerException - if event is null

broadcast

public void broadcast(javax.faces.event.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 UIComponentBase
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
java.lang.IllegalArgumentException - if the implementation class of this FacesEvent is not supported by this component
java.lang.NullPointerException - if event is null

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.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 UIComponentBase
Parameters:
context - FacesContext for the current request
Throws:
java.io.IOException - if an input/output error occurs while rendering
java.lang.NullPointerException - if context is null

processDecodes

public void processDecodes(javax.faces.context.FacesContext context)

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

Overrides:
processDecodes in class UIComponentBase
Parameters:
context - FacesContext for the current request
Throws:
java.lang.NullPointerException - if context is null

processValidators

public void processValidators(javax.faces.context.FacesContext context)

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

Overrides:
processValidators in class UIComponentBase
Parameters:
context - FacesContext for the current request
Throws:
java.lang.NullPointerException - if context is null

processUpdates

public void processUpdates(javax.faces.context.FacesContext context)

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

Overrides:
processUpdates in class UIComponentBase
Parameters:
context - FacesContext for the current request
Throws:
java.lang.NullPointerException - if context is null


Copyright ? 2002-2004 Sun Microsystems, Inc. All Rights Reserved.