org.openfaces.component
Class OUIData

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by javax.faces.component.UIData
              extended by org.openfaces.component.OUIData
All Implemented Interfaces:
java.util.EventListener, javax.faces.component.NamingContainer, javax.faces.component.PartialStateHolder, javax.faces.component.StateHolder, javax.faces.component.UniqueIdVendor, javax.faces.event.ComponentSystemEventListener, javax.faces.event.FacesListener, javax.faces.event.SystemEventListenerHolder, OUIComponent
Direct Known Subclasses:
AbstractTable

public class OUIData
extends javax.faces.component.UIData
implements javax.faces.component.NamingContainer, javax.faces.component.UniqueIdVendor, OUIComponent

This is a modified version of the UIData class copied from MyFaces 2.0.2. Here's a list of modifications from the original version:

Represents an abstraction of a component which has multiple "rows" of data.

The children of this component are expected to be UIColumn components.

Note that the same set of child components are reused to implement each row of the table in turn during such phases as apply-request-values and render-response. Altering any of the members of these components therefore affects the attribute for every row, except for the following members:

This reuse of the child components also means that it is not possible to save a reference to a component during table processing, then access it later and expect it to still represent the same row of the table.

Implementation Notes

Each of the UIColumn children of this component has a few component children of its own to render the contents of the table cell. However there can be a very large number of rows in a table, so it isn't efficient for the UIColumn and all its child objects to be duplicated for each row in the table. Instead the "flyweight" pattern is used where a serialized state is held for each row. When setRowIndex is invoked, the UIColumn objects and their children serialize their current state then reinitialise themselves from the appropriate saved state. This allows a single set of real objects to represent multiple objects which have the same types but potentially different internal state. When a row is selected for the first time, its state is set to a clean "initial" state. Transient components (including any read-only component) do not save their state; they are just reinitialised as required. The state saved/restored when changing rows is not the complete component state, just the fields that are expected to vary between rows: "submittedValue", "value", "isValid".

Note that a table is a "naming container", so that components within the table have their ids prefixed with the id of the table. Actually, when setRowIndex has been called on a table with id of "zzz" the table pretends to its children that its ID is "zzz_n" where n is the row index. This means that renderers for child components which call component.getClientId automatically get ids of form "zzz_n:childId" thus ensuring that components in different rows of the table get different ids.

When decoding a submitted page, this class iterates over all its possible rowIndex values, restoring the appropriate serialized row state then calling processDecodes on the child components. Because the child components (or their renderers) use getClientId to get the request key to look for parameter data, and because this object pretends to have a different id per row ("zzz_n") a single child component can decode data from each table row in turn without being aware that it is within a table. The table's data model is updated before each call to child.processDecodes, so the child decode method can assume that the data model's rowData points to the model object associated with the row currently being decoded. Exactly the same process applies for the later validation and updateModel phases.

When the data model for the table is bound to a backing bean property, and no validation errors have occured during processing of a postback, the data model is refetched at the start of the rendering phase (ie after the update model phase) so that the contents of the data model can be changed as a result of the latest form submission. Because the saved row state must correspond to the elements within the data model, the row state must be discarded whenever a new data model is fetched; not doing this would cause all sorts of inconsistency issues. This does imply that changing the state of any of the members "submittedValue", "value" or "valid" of a component within the table during the invokeApplication phase has no effect on the rendering of the table. When a validation error has occurred, a new DataModel is not fetched, and the saved state of the child components is not discarded.

see Javadoc of the JSF Specification for more information.


Field Summary
static java.lang.String COMPONENT_FAMILY
           
static java.lang.String COMPONENT_TYPE
           
 
Fields inherited from class javax.faces.component.UIComponent
BEANINFO_KEY, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, VIEW_LOCATION_KEY
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
OUIData()
          Construct an instance of the UIData.
 
Method Summary
 void broadcast(javax.faces.event.FacesEvent event)
          Ensure that before the event's listeners are invoked this UIData component's "current row" is set to the row associated with the event.
 java.lang.String createUniqueId(javax.faces.context.FacesContext context, java.lang.String seed)
          
 void encodeBegin(javax.faces.context.FacesContext context)
          Perform necessary actions when rendering of this component starts, before delegating to the inherited implementation which calls the associated renderer's encodeBegin method.
 void encodeEnd(javax.faces.context.FacesContext context)
           
 java.lang.String getFamily()
           
 int getFirst()
          Defines the index of the first row to be displayed, starting from 0.
 javax.faces.component.UIComponent getFooter()
           
 javax.faces.component.UIComponent getHeader()
           
 java.lang.String getOnblur()
           
 java.lang.String getOnclick()
           
 java.lang.String getOncontextmenu()
           
 java.lang.String getOndblclick()
           
 java.lang.String getOnfocus()
           
 java.lang.String getOnkeydown()
           
 java.lang.String getOnkeypress()
           
 java.lang.String getOnkeyup()
           
 java.lang.String getOnmousedown()
           
 java.lang.String getOnmousemove()
           
 java.lang.String getOnmouseout()
           
 java.lang.String getOnmouseover()
           
 java.lang.String getOnmouseup()
           
 java.lang.String getRolloverClass()
           
 java.lang.String getRolloverStyle()
           
 int getRowCount()
           
 java.lang.Object getRowData()
           
 int getRowIndex()
           
 int getRows()
          Defines the maximum number of rows of data to be displayed.
 java.lang.String getStyle()
           
 java.lang.String getStyleClass()
           
 java.lang.Object getUiDataValue()
          An EL expression that specifies the data model that backs this table.
 java.lang.String getVar()
          Defines the name of the request-scope variable that will hold the current row during iteration.
 boolean invokeOnComponent(javax.faces.context.FacesContext context, java.lang.String clientId, javax.faces.component.ContextCallback callback)
           
 boolean isRowAvailable()
           
 boolean isRowAvailableAfterRestoring(int rowIndex)
           
 void processDecodes(javax.faces.context.FacesContext context)
           
 void processUpdates(javax.faces.context.FacesContext context)
           
 void processValidators(javax.faces.context.FacesContext context)
           
 void queueEvent(javax.faces.event.FacesEvent event)
          Modify events queued for any child components so that the UIData state will be correctly configured before the event's listeners are executed.
static void restoreDescendantComponentStates(java.util.Iterator<javax.faces.component.UIComponent> childIterator, java.lang.Object state, boolean restoreChildFacets)
          Overwrite the state of the child components of this component with data previously saved by method saveDescendantComponentStates.
static java.util.Collection<java.lang.Object[]> saveDescendantComponentStates(java.util.Iterator<javax.faces.component.UIComponent> childIterator, boolean saveChildFacets)
          Walk the tree of child components of this UIData, saving the parts of their state that can vary between rows.
 void setFirst(int first)
           
 void setFooter(javax.faces.component.UIComponent footer)
           
 void setHeader(javax.faces.component.UIComponent header)
           
 void setOnblur(java.lang.String onblur)
           
 void setOnclick(java.lang.String onclick)
           
 void setOncontextmenu(java.lang.String oncontextmenu)
           
 void setOndblclick(java.lang.String ondblclick)
           
 void setOnfocus(java.lang.String onfocus)
           
 void setOnkeydown(java.lang.String onkeydown)
           
 void setOnkeypress(java.lang.String onkeypress)
           
 void setOnkeyup(java.lang.String onkeyup)
           
 void setOnmousedown(java.lang.String onmousedown)
           
 void setOnmousemove(java.lang.String onmousemove)
           
 void setOnmouseout(java.lang.String onmouseout)
           
 void setOnmouseover(java.lang.String onmouseover)
           
 void setOnmouseup(java.lang.String onmouseup)
           
 void setRolloverClass(java.lang.String rolloverClass)
           
 void setRolloverStyle(java.lang.String rolloverStyle)
           
 void setRowIndex(int rowIndex)
          Set the current row index that methods like getRowData use.
 void setRows(int rows)
          Set the maximum number of rows displayed in the table.
 void setStyle(java.lang.String style)
           
 void setStyleClass(java.lang.String styleClass)
           
 void setUiDataValue(java.lang.Object value)
           
 void setValueExpression(java.lang.String name, javax.el.ValueExpression binding)
           
 void setVar(java.lang.String var)
           
 boolean visitTree(javax.faces.component.visit.VisitContext context, javax.faces.component.visit.VisitCallback callback)
          Overrides the behavior in UIComponent.visitTree(javax.faces.component.visit.VisitContext, javax.faces.component.visit.VisitCallback) to handle iteration correctly.
 
Methods inherited from class javax.faces.component.UIData
getClientId, getValue, setValue, setValueBinding
 
Methods inherited from class javax.faces.component.UIComponentBase
addClientBehavior, clearInitialState, decode, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getDefaultEventName, getEventNames, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRendererType, getRendersChildren, getValueBinding, isRendered, isTransient, markInitialState, processRestoreState, processSaveState, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient
 
Methods inherited from class javax.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getValueExpression, initialStateMarked, isCompositeComponent, isInView, popComponentFromEL, processEvent, pushComponentToEL, setInView, subscribeToEvent, unsubscribeFromEvent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_FAMILY

public static final java.lang.String COMPONENT_FAMILY
See Also:
Constant Field Values

COMPONENT_TYPE

public static final java.lang.String COMPONENT_TYPE
See Also:
Constant Field Values
Constructor Detail

OUIData

public OUIData()
Construct an instance of the UIData.

Method Detail

invokeOnComponent

public boolean invokeOnComponent(javax.faces.context.FacesContext context,
                                 java.lang.String clientId,
                                 javax.faces.component.ContextCallback callback)
                          throws javax.faces.FacesException
Overrides:
invokeOnComponent in class javax.faces.component.UIData
Throws:
javax.faces.FacesException

setFooter

public void setFooter(javax.faces.component.UIComponent footer)
Overrides:
setFooter in class javax.faces.component.UIData

getFooter

public javax.faces.component.UIComponent getFooter()
Overrides:
getFooter in class javax.faces.component.UIData

setHeader

public void setHeader(javax.faces.component.UIComponent header)
Overrides:
setHeader in class javax.faces.component.UIData

getHeader

public javax.faces.component.UIComponent getHeader()
Overrides:
getHeader in class javax.faces.component.UIData

isRowAvailable

public boolean isRowAvailable()
Overrides:
isRowAvailable in class javax.faces.component.UIData

getRowCount

public int getRowCount()
Overrides:
getRowCount in class javax.faces.component.UIData

getRowData

public java.lang.Object getRowData()
Overrides:
getRowData in class javax.faces.component.UIData

getRowIndex

public int getRowIndex()
Overrides:
getRowIndex in class javax.faces.component.UIData

setRowIndex

public void setRowIndex(int rowIndex)
Set the current row index that methods like getRowData use.

Param rowIndex can be -1, meaning "no row".

Overrides:
setRowIndex in class javax.faces.component.UIData
Parameters:
rowIndex -

restoreDescendantComponentStates

public static void restoreDescendantComponentStates(java.util.Iterator<javax.faces.component.UIComponent> childIterator,
                                                    java.lang.Object state,
                                                    boolean restoreChildFacets)
Overwrite the state of the child components of this component with data previously saved by method saveDescendantComponentStates.

The saved state info only covers those fields that are expected to vary between rows of a table. Other fields are not modified.


saveDescendantComponentStates

public static java.util.Collection<java.lang.Object[]> saveDescendantComponentStates(java.util.Iterator<javax.faces.component.UIComponent> childIterator,
                                                                                     boolean saveChildFacets)
Walk the tree of child components of this UIData, saving the parts of their state that can vary between rows.

This is very similar to the process that occurs for normal components when the view is serialized. Transient components are skipped (no state is saved for them).

If there are no children then null is returned. If there are one or more children, and all children are transient then an empty collection is returned; this will happen whenever a table contains only read-only components.

Otherwise a collection is returned which contains an object for every non-transient child component; that object may itself contain a collection of the state of that child's child components.


setValueExpression

public void setValueExpression(java.lang.String name,
                               javax.el.ValueExpression binding)
Overrides:
setValueExpression in class javax.faces.component.UIData

queueEvent

public void queueEvent(javax.faces.event.FacesEvent event)
Modify events queued for any child components so that the UIData state will be correctly configured before the event's listeners are executed.

Child components or their renderers may register events against those child components. When the listener for that event is eventually invoked, it may expect the uidata's rowData and rowIndex to be referring to the same object that caused the event to fire.

The original queueEvent call against the child component has been forwarded up the chain of ancestors in the standard way, making it possible here to wrap the event in a new event whose source is this component, not the original one. When the event finally is executed, this component's broadcast method is invoked, which ensures that the UIData is set to be at the correct row before executing the original event.

Overrides:
queueEvent in class javax.faces.component.UIData

broadcast

public void broadcast(javax.faces.event.FacesEvent event)
               throws javax.faces.event.AbortProcessingException
Ensure that before the event's listeners are invoked this UIData component's "current row" is set to the row associated with the event.

See queueEvent for more details.

Overrides:
broadcast in class javax.faces.component.UIData
Throws:
javax.faces.event.AbortProcessingException

createUniqueId

public java.lang.String createUniqueId(javax.faces.context.FacesContext context,
                                       java.lang.String seed)

Specified by:
createUniqueId in interface javax.faces.component.UniqueIdVendor
Overrides:
createUniqueId in class javax.faces.component.UIData
Since:
2.0

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.IOException
Perform necessary actions when rendering of this component starts, before delegating to the inherited implementation which calls the associated renderer's encodeBegin method.

Overrides:
encodeBegin in class javax.faces.component.UIData
Throws:
java.io.IOException

encodeEnd

public void encodeEnd(javax.faces.context.FacesContext context)
               throws java.io.IOException
Overrides:
encodeEnd in class javax.faces.component.UIComponentBase
Throws:
java.io.IOException
See Also:
UIComponentBase.encodeEnd(javax.faces.context.FacesContext)

processDecodes

public void processDecodes(javax.faces.context.FacesContext context)
Overrides:
processDecodes in class javax.faces.component.UIData

processValidators

public void processValidators(javax.faces.context.FacesContext context)
Overrides:
processValidators in class javax.faces.component.UIData

processUpdates

public void processUpdates(javax.faces.context.FacesContext context)
Overrides:
processUpdates in class javax.faces.component.UIData

getUiDataValue

public java.lang.Object getUiDataValue()
An EL expression that specifies the data model that backs this table.

The value referenced by the EL expression can be of any type.

Note in particular that unordered collections, eg Set are not supported. Therefore if the value expression references such an object then the table will be considered to contain just one element - the collection itself.


setUiDataValue

public void setUiDataValue(java.lang.Object value)

getFirst

public int getFirst()
Defines the index of the first row to be displayed, starting from 0.

Overrides:
getFirst in class javax.faces.component.UIData

setFirst

public void setFirst(int first)
Overrides:
setFirst in class javax.faces.component.UIData

getRows

public int getRows()
Defines the maximum number of rows of data to be displayed.

Specify zero to display all rows from the "first" row to the end of available data.

Overrides:
getRows in class javax.faces.component.UIData

setRows

public void setRows(int rows)
Set the maximum number of rows displayed in the table.

Overrides:
setRows in class javax.faces.component.UIData

getVar

public java.lang.String getVar()
Defines the name of the request-scope variable that will hold the current row during iteration.

During rendering of child components of this UIData, the variable with this name can be read to learn what the "rowData" object for the row currently being rendered is.

This value must be a static value, ie an EL expression is not permitted.

Overrides:
getVar in class javax.faces.component.UIData

visitTree

public boolean visitTree(javax.faces.component.visit.VisitContext context,
                         javax.faces.component.visit.VisitCallback callback)
Overrides the behavior in UIComponent.visitTree(javax.faces.component.visit.VisitContext, javax.faces.component.visit.VisitCallback) to handle iteration correctly.

Overrides:
visitTree in class javax.faces.component.UIData
Parameters:
context - the visit context which handles the processing details
callback - the callback to be performed
Returns:
false if the processing is not done true if we can shortcut the visiting because we are done with everything
Since:
2.0

setVar

public void setVar(java.lang.String var)
Overrides:
setVar in class javax.faces.component.UIData

getFamily

public java.lang.String getFamily()
Overrides:
getFamily in class javax.faces.component.UIData

isRowAvailableAfterRestoring

public boolean isRowAvailableAfterRestoring(int rowIndex)

getStyle

public java.lang.String getStyle()
Specified by:
getStyle in interface OUIComponent

setStyle

public void setStyle(java.lang.String style)
Specified by:
setStyle in interface OUIComponent

getRolloverStyle

public java.lang.String getRolloverStyle()
Specified by:
getRolloverStyle in interface OUIComponent

setRolloverStyle

public void setRolloverStyle(java.lang.String rolloverStyle)
Specified by:
setRolloverStyle in interface OUIComponent

getRolloverClass

public java.lang.String getRolloverClass()
Specified by:
getRolloverClass in interface OUIComponent

setRolloverClass

public void setRolloverClass(java.lang.String rolloverClass)
Specified by:
setRolloverClass in interface OUIComponent

getStyleClass

public java.lang.String getStyleClass()
Specified by:
getStyleClass in interface OUIComponent

setStyleClass

public void setStyleClass(java.lang.String styleClass)
Specified by:
setStyleClass in interface OUIComponent

getOnkeypress

public java.lang.String getOnkeypress()
Specified by:
getOnkeypress in interface OUIComponent

setOnkeypress

public void setOnkeypress(java.lang.String onkeypress)
Specified by:
setOnkeypress in interface OUIComponent

getOncontextmenu

public java.lang.String getOncontextmenu()
Specified by:
getOncontextmenu in interface OUIComponent

setOncontextmenu

public void setOncontextmenu(java.lang.String oncontextmenu)
Specified by:
setOncontextmenu in interface OUIComponent

getOnclick

public java.lang.String getOnclick()
Specified by:
getOnclick in interface OUIComponent

setOnclick

public void setOnclick(java.lang.String onclick)
Specified by:
setOnclick in interface OUIComponent

getOndblclick

public java.lang.String getOndblclick()
Specified by:
getOndblclick in interface OUIComponent

setOndblclick

public void setOndblclick(java.lang.String ondblclick)
Specified by:
setOndblclick in interface OUIComponent

getOnmousedown

public java.lang.String getOnmousedown()
Specified by:
getOnmousedown in interface OUIComponent

setOnmousedown

public void setOnmousedown(java.lang.String onmousedown)
Specified by:
setOnmousedown in interface OUIComponent

getOnmouseover

public java.lang.String getOnmouseover()
Specified by:
getOnmouseover in interface OUIComponent

setOnmouseover

public void setOnmouseover(java.lang.String onmouseover)
Specified by:
setOnmouseover in interface OUIComponent

getOnmousemove

public java.lang.String getOnmousemove()
Specified by:
getOnmousemove in interface OUIComponent

setOnmousemove

public void setOnmousemove(java.lang.String onmousemove)
Specified by:
setOnmousemove in interface OUIComponent

getOnmouseout

public java.lang.String getOnmouseout()
Specified by:
getOnmouseout in interface OUIComponent

setOnmouseout

public void setOnmouseout(java.lang.String onmouseout)
Specified by:
setOnmouseout in interface OUIComponent

getOnmouseup

public java.lang.String getOnmouseup()
Specified by:
getOnmouseup in interface OUIComponent

setOnmouseup

public void setOnmouseup(java.lang.String onmouseup)
Specified by:
setOnmouseup in interface OUIComponent

getOnfocus

public java.lang.String getOnfocus()
Specified by:
getOnfocus in interface OUIComponent

setOnfocus

public void setOnfocus(java.lang.String onfocus)
Specified by:
setOnfocus in interface OUIComponent

getOnblur

public java.lang.String getOnblur()
Specified by:
getOnblur in interface OUIComponent

setOnblur

public void setOnblur(java.lang.String onblur)
Specified by:
setOnblur in interface OUIComponent

getOnkeydown

public java.lang.String getOnkeydown()
Specified by:
getOnkeydown in interface OUIComponent

setOnkeydown

public void setOnkeydown(java.lang.String onkeydown)
Specified by:
setOnkeydown in interface OUIComponent

getOnkeyup

public java.lang.String getOnkeyup()
Specified by:
getOnkeyup in interface OUIComponent

setOnkeyup

public void setOnkeyup(java.lang.String onkeyup)
Specified by:
setOnkeyup in interface OUIComponent


Copyright © 1998-2010 TeamDev Ltd. All Rights Reserved.