Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]
javax.faces.component
public class: UIData [javadoc | source]
java.lang.Object
   javax.faces.component.UIComponent
      javax.faces.component.UIComponentBase
         javax.faces.component.UIData

All Implemented Interfaces:
    UniqueIdVendor, NamingContainer, PartialStateHolder, ComponentSystemEventListener, SystemEventListenerHolder

Direct Known Subclasses:
    HtmlDataTable

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 ValueExpression ). 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.

Nested Class Summary:
enum class  UIData.PropertyKeys  Properties that are tracked by state saving. 
Field Summary
public static final  String COMPONENT_TYPE   

The standard component type for this component.

 
public static final  String COMPONENT_FAMILY   

The standard component family for this component.

 
Fields inherited from javax.faces.component.UIComponent:
CURRENT_COMPONENT,  CURRENT_COMPOSITE_COMPONENT,  BEANINFO_KEY,  FACETS_KEY,  VIEW_LOCATION_KEY,  COMPOSITE_COMPONENT_TYPE_KEY,  COMPOSITE_FACET_NAME,  attributesThatAreSet,  stateHelper,  compositeParent,  bindings,  initialState,  listenersByEventClass
Constructor:
 public UIData() 
Method from javax.faces.component.UIData Summary:
broadcast,   createUniqueId,   encodeBegin,   getClientId,   getDataModel,   getFamily,   getFirst,   getFooter,   getHeader,   getRowCount,   getRowData,   getRowIndex,   getRows,   getValue,   getVar,   invokeOnComponent,   isRowAvailable,   processDecodes,   processUpdates,   processValidators,   queueEvent,   setDataModel,   setFirst,   setFooter,   setHeader,   setRowIndex,   setRows,   setValue,   setValueBinding,   setValueExpression,   setVar,   visitTree
Methods from javax.faces.component.UIComponentBase:
addClientBehavior,   addFacesListener,   broadcast,   clearInitialState,   decode,   encodeBegin,   encodeChildren,   encodeEnd,   findComponent,   getAttributes,   getChildCount,   getChildren,   getClientBehaviors,   getClientId,   getDefaultEventName,   getDescriptorMap,   getEventNames,   getFacesContext,   getFacesListeners,   getFacet,   getFacetCount,   getFacets,   getFacetsAndChildren,   getId,   getParent,   getRenderer,   getRendererType,   getRendersChildren,   getValueBinding,   invokeOnComponent,   isRendered,   isTransient,   markInitialState,   processDecodes,   processRestoreState,   processSaveState,   processUpdates,   processValidators,   queueEvent,   removeFacesListener,   restoreAttachedState,   restoreState,   saveAttachedState,   saveState,   setId,   setParent,   setRendered,   setRendererType,   setTransient,   setValueBinding
Methods from javax.faces.component.UIComponent:
addFacesListener,   broadcast,   clearInitialState,   decode,   encodeAll,   encodeBegin,   encodeChildren,   encodeEnd,   findComponent,   getAttributes,   getChildCount,   getChildren,   getClientId,   getClientId,   getCompositeComponentParent,   getContainerClientId,   getCurrentComponent,   getCurrentCompositeComponent,   getFacesContext,   getFacesListeners,   getFacet,   getFacetCount,   getFacets,   getFacetsAndChildren,   getFamily,   getId,   getListenersForEventClass,   getNamingContainer,   getParent,   getRenderer,   getRendererType,   getRendersChildren,   getResourceBundleMap,   getStateHelper,   getStateHelper,   getValueBinding,   getValueExpression,   initialStateMarked,   invokeOnComponent,   isCompositeComponent,   isInView,   isRendered,   isVisitable,   markInitialState,   popComponentFromEL,   processDecodes,   processEvent,   processRestoreState,   processSaveState,   processUpdates,   processValidators,   pushComponentToEL,   queueEvent,   removeFacesListener,   setId,   setInView,   setParent,   setRendered,   setRendererType,   setValueBinding,   setValueExpression,   subscribeToEvent,   unsubscribeFromEvent,   visitTree
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.faces.component.UIData Detail:
 public  void broadcast(FacesEvent event) throws AbortProcessingException 

    Override the default UIComponentBase#broadcast 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.

 public String createUniqueId(FacesContext context,
    String seed) 
 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.

 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 ).

 protected DataModel getDataModel() 

    Return the internal DataModel object representing the data objects that we will iterate over in this component's rendering.

    If the model has been cached by a previous call to #setDataModel , return it. Otherwise call #getValue . If the result is null, create an empty ListDataModel and return it. If the result is an instance of DataModel , return it. Otherwise, adapt the result as described in #getValue and return it.

 public String getFamily() 
 public int getFirst() 

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

 public UIComponent getFooter() 

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

 public UIComponent getHeader() 

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

 public int getRowCount() 

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

 public Object getRowData() 

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

 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.

 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.

 public 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:

    • Arrays
    • java.util.List
    • java.sql.ResultSet
    • javax.servlet.jsp.jstl.sql.Result

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

 public 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.

 public boolean invokeOnComponent(FacesContext context,
    String clientId,
    ContextCallback callback) throws FacesException 

    Override behavior from UIComponentBase#invokeOnComponent to provide special care for positioning the data properly before finding the component and invoking the callback on it. If the argument clientId is equal to this.getClientId() simply invoke the contextCallback, passing the context argument and this as arguments, and return true. If the argument clientId is not equal to this.getClientId(), inspect each of the facet children of this UIData instance and for each one, compare its clientId with the argument clientId. If there is a match, invoke the contextCallback, passing the context argument and this as arguments, and return true. Otherwise, attempt to extract a rowIndex from the clientId. For example, if the argument clientId was form:data:3:customerHeader the rowIndex would be 3. Let this value be called newIndex. The current rowIndex of this instance must be saved aside and restored before returning in all cases, regardless of the outcome of the search or if any exceptions are thrown in the process.

    The implementation of this method must never return true if setting the rowIndex of this instance to be equal to newIndex causes this instance to return false from #isRowAvailable .

 public boolean isRowAvailable() 

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

 public  void processDecodes(FacesContext context) 

    Override the default UIComponentBase#processDecodes 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.
 public  void processUpdates(FacesContext context) 

    Override the default UIComponentBase#processUpdates 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.
 public  void processValidators(FacesContext context) 

    Override the default UIComponentBase#processValidators 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.
 public  void queueEvent(FacesEvent event) 

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

 protected  void setDataModel(DataModel dataModel) 

    Set the internal DataModel. This UIData instance must use the given DataModel as its internal value representation from now until the next call to setDataModel. If the given DataModel is null, the internal DataModel must be reset in a manner so that the next call to #getDataModel causes lazy instantion of a newly refreshed DataModel.

    Subclasses might call this method if they either want to restore the internal DataModel during the Restore View phase or if they want to explicitly refresh the current DataModel for the Render Response phase.

 public  void setFirst(int first) 

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

 public  void setFooter(UIComponent footer) 

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

 public  void setHeader(UIComponent header) 

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

 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.
 public  void setRows(int rows) 

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

 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 .

 public  void setValueBinding(String name,
    ValueBinding binding) 
Deprecated! This - has been replaced by #setValueExpression(java.lang.String, javax.el.ValueExpression) .

    If "name" is something other than "value", "var", or "rowIndex", rely on the superclass conversion from ValueBinding to ValueExpression.

 public  void setValueExpression(String name,
    ValueExpression binding) 

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

 public  void setVar(String var) 

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

 public boolean visitTree(VisitContext context,
    VisitCallback callback) 

    Override the behavior in UIComponent#visitTree to handle iteration correctly.

    If the UIComponent#isVisitable method of this instance returns false, take no action and return.

    Otherwise, save aside the result of a call to #getRowIndex . Call UIComponent#pushComponentToEL and invoke the visit callback on this UIData instance as described in UIComponent#visitTree . Let the result of the invoctaion be visitResult. If visitResult is VisitResult#COMPLETE , take no further action and return true. Otherwise, determine if we need to visit our children. The default implementation calls VisitContext#getSubtreeIdsToVisit passing this as the argument. If the result of that call is non-empty, let doVisitChildren be true. If doVisitChildren is true and visitResult is VisitResult#ACCEPT , take the following action.

    • If this component has facets, call UIComponent#getFacets on this instance and invoke the values() method. For each UIComponent in the returned Map, call UIComponent#visitTree .

    • If this component has children, for each child UIComponent retured from calling #getChildren on this instance, if the child has facets, call UIComponent#getFacets on the child instance and invoke the values() method. For each UIComponent in the returned Map, call UIComponent#visitTree .

    • Iterate over the columns and rows.

      • Let rowsToProcess be the return from #getRows .

      • Let rowIndex be the return from #getFirst - 1.

      • While the number of rows processed is less than rowsToProcess, take the following actions.

        Call #setRowIndex , passing the current row index.

        If #isRowAvailable returns false, take no further action and return false.

        For each child component of this UIData that is also an instance of UIColumn , call UIComponent#visitTree on the child. If such a call returns true, terminate iteration and return true. Take no action on non UIColumn children.

    Call #popComponentFromEL and restore the saved row index with a call to #setRowIndex .

    Return false to allow the visiting to continue.