org.ajax4jsf.component
Class UIDataAdaptor

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by javax.faces.component.UIData
              extended by org.ajax4jsf.component.UIDataAdaptor
All Implemented Interfaces:
javax.faces.component.NamingContainer, javax.faces.component.StateHolder, org.ajax4jsf.component.AjaxChildrenEncoder, org.ajax4jsf.component.AjaxDataEncoder
Direct Known Subclasses:
SequenceDataAdaptor

public abstract class UIDataAdaptor
extends javax.faces.component.UIData
implements org.ajax4jsf.component.AjaxDataEncoder

Base class for iterable components, like dataTable, Tomahawk dataList, Facelets repeat, tree etc., with support for partial rendering on AJAX responces for one or more selected iterations.

Author:
shura

Nested Class Summary
protected  class UIDataAdaptor.ComponentVisitor
          Base class for visit data model at phases decode, validation and update model
protected static class UIDataAdaptor.IndexedEvent
          Wrapper for event from child component, with value of current row key.
 
Field Summary
static java.lang.String COMPONENT_STATE_ATTRIBUTE
           
protected  UIDataAdaptor.ComponentVisitor decodeVisitor
          Visitor for process decode on children components.
static javax.faces.model.DataModel EMPTY_MODEL
           
protected  UIDataAdaptor.ComponentVisitor updateVisitor
          Visitor for process update model phase.
protected  UIDataAdaptor.ComponentVisitor validateVisitor
          Visitor for process validation phase
 
Fields inherited from class javax.faces.component.UIData
COMPONENT_FAMILY, COMPONENT_TYPE
 
Fields inherited from class javax.faces.component.UIComponent
bindings
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
UIDataAdaptor()
           
 
Method Summary
protected  void addAjaxKeyEvent(javax.faces.event.FacesEvent event)
           
 void addRequestKey(java.lang.Object key)
          Adds argument key to AJAX internal request keys set
 void beforeRenderResponse(javax.faces.context.FacesContext context)
           
 void broadcast(javax.faces.event.FacesEvent event)
           
protected  boolean broadcastLocal(javax.faces.event.FacesEvent event)
          Process events targetted for concrete implementation.
 void captureOrigValue()
          Save current state of data variable.
 void captureOrigValue(javax.faces.context.FacesContext faces)
          Save current state of data variable.
 void clearRequestKeysSet()
          Clears AJAX internal request keys set
 boolean containsRequestKey(java.lang.Object key)
          Checks whether AJAX internal request keys set contains argument key
protected abstract  org.ajax4jsf.model.DataComponentState createComponentState()
          Hook method for create default state in concrete implementations.
protected abstract  org.ajax4jsf.model.ExtendedDataModel createDataModel()
          Hook mathod for create data model in concrete implementations.
protected abstract  java.util.Iterator<javax.faces.component.UIComponent> dataChildren()
          This method must create iterator for all children components, processed "per row" It can be children of UIColumn in dataTable, nodes in tree
 void encodeAjaxChild(javax.faces.context.FacesContext context, java.lang.String path, java.util.Set<java.lang.String> ids, java.util.Set<java.lang.String> renderedAreas)
           
 void encodeBegin(javax.faces.context.FacesContext context)
           
protected  java.lang.String extractKeySegment(javax.faces.context.FacesContext context, java.lang.String tailId)
          Extracts segment of component client identifier containing row key
protected abstract  java.util.Iterator<javax.faces.component.UIComponent> fixedChildren()
          This method must create iterator for all non-data avare children of this component ( header/footer facets for components and columns in dataTable, facets for tree etc.
 java.util.Set<java.lang.Object> getAjaxKeys()
           
 java.util.Set<java.lang.Object> getAllAjaxKeys()
           
 java.lang.String getBaseClientId(javax.faces.context.FacesContext faces)
          Get base clietntId of this component ( withowt iteration part )
protected  AjaxChildrenRenderer getChildrenRenderer()
          getter for simple AjaxChildrenRenderer instance in case of ajax responses.
protected  java.util.Map<java.lang.String,org.ajax4jsf.component.UIDataAdaptor.SavedState> getChildState(javax.faces.context.FacesContext faces)
           
 java.lang.String getClientId(javax.faces.context.FacesContext faces)
           
 org.ajax4jsf.model.DataComponentState getComponentState()
           
protected  java.util.Set<java.lang.String> getEncodedIds()
           
protected  org.ajax4jsf.model.ExtendedDataModel getExtendedDataModel()
          Get current data model, or create it by createDataModel() method.
 int getRowCount()
           
 java.lang.Object getRowData()
           
 int getRowIndex()
           
 java.lang.Object getRowKey()
          Same as for int index, but for complex model key.
 javax.faces.convert.Converter getRowKeyConverter()
           
 java.lang.String getRowKeyVar()
           
 java.lang.String getStateVar()
          Get name of EL variable for component state.
 java.lang.Object getValue()
           
protected  java.util.Iterator<javax.faces.component.UIComponent> invocableChildren()
          Returns iterator of components to search through in invokeOnComponent(FacesContext, String, ContextCallback).
 boolean invokeOnComponent(javax.faces.context.FacesContext context, java.lang.String clientId, javax.faces.component.ContextCallback callback)
           
 boolean isRowAvailable()
           
protected  void iterate(javax.faces.context.FacesContext faces, UIDataAdaptor.ComponentVisitor visitor, java.lang.Object argument)
          Perform iteration on all children components and all data rows with given visitor.
protected  boolean keepSaved(javax.faces.context.FacesContext context)
          Check for validation errors on children components.
 void processDecodes(javax.faces.context.FacesContext faces)
           
protected  void processDecodes(javax.faces.context.FacesContext faces, java.lang.Object argument)
           
 void processUpdates(javax.faces.context.FacesContext faces)
           
protected  void processUpdates(javax.faces.context.FacesContext faces, java.lang.Object argument)
           
 void processValidators(javax.faces.context.FacesContext faces)
           
protected  void processValidators(javax.faces.context.FacesContext faces, java.lang.Object argument)
           
 void queueEvent(javax.faces.event.FacesEvent event)
           
 void removeRequestKey(java.lang.Object key)
          Removes argument key from AJAX internal request keys set
protected  void resetComponent(javax.faces.context.FacesContext faces)
          Reset per-request fields in component.
protected  void resetDataModel()
          Reset data model.
protected  void restoreChildState(javax.faces.context.FacesContext faces)
          Restore values of EditableValueHolder fields after change current row.
 void restoreOrigValue()
          Restore value of data variable after processing phase.
 void restoreOrigValue(javax.faces.context.FacesContext faces)
          Restore value of data variable after processing phase.
 void restoreState(javax.faces.context.FacesContext faces, java.lang.Object object)
           
protected  void saveChildState(javax.faces.context.FacesContext faces)
          Save values of EditableValueHolder fields before change current row.
 java.lang.Object saveState(javax.faces.context.FacesContext faces)
           
 void setAjaxKeys(java.util.Set<java.lang.Object> ajaxKeys)
           
 void setComponentState(org.ajax4jsf.model.DataComponentState state)
          Set current state ( at most cases, visual representation ) of this component.
protected  void setExtendedDataModel(org.ajax4jsf.model.ExtendedDataModel model)
          Set data model.
 void setId(java.lang.String id)
           
 void setParent(javax.faces.component.UIComponent parent)
           
 void setRowIndex(int index)
           
 void setRowKey(javax.faces.context.FacesContext faces, java.lang.Object key)
          Setup current row by key.
 void setRowKey(java.lang.Object key)
           
 void setRowKeyConverter(javax.faces.convert.Converter rowKeyConverter)
           
 void setRowKeyVar(java.lang.String rowKeyVar)
           
 void setStateVar(java.lang.String varStatus)
           
protected  void setupVariable(javax.faces.context.FacesContext faces, javax.faces.model.DataModel localModel, boolean rowSelected)
          Setup EL variable for different iteration.
 void setValue(java.lang.Object value)
           
 void walk(javax.faces.context.FacesContext faces, org.ajax4jsf.model.DataVisitor visitor, java.lang.Object argument)
          Walk ( visit ) this component on all data-avare children for each row.
 
Methods inherited from class javax.faces.component.UIData
getDataModel, getFamily, getFirst, getFooter, getHeader, getRows, getVar, setDataModel, setFirst, setFooter, setHeader, setRows, setValueBinding, setValueExpression, setVar
 
Methods inherited from class javax.faces.component.UIComponentBase
addFacesListener, decode, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, isRendered, isTransient, processRestoreState, processSaveState, removeFacesListener, restoreAttachedState, saveAttachedState, setRendered, setRendererType, setTransient
 
Methods inherited from class javax.faces.component.UIComponent
encodeAll, getContainerClientId, getValueExpression
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_STATE_ATTRIBUTE

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

EMPTY_MODEL

public static final javax.faces.model.DataModel EMPTY_MODEL

decodeVisitor

protected UIDataAdaptor.ComponentVisitor decodeVisitor
Visitor for process decode on children components.


validateVisitor

protected UIDataAdaptor.ComponentVisitor validateVisitor
Visitor for process validation phase


updateVisitor

protected UIDataAdaptor.ComponentVisitor updateVisitor
Visitor for process update model phase.

Constructor Detail

UIDataAdaptor

public UIDataAdaptor()
Method Detail

getStateVar

public java.lang.String getStateVar()
Get name of EL variable for component state.

Returns:
the varState

setStateVar

public void setStateVar(java.lang.String varStatus)
Parameters:
varStatus - the varStatus to set

getRowKeyVar

public java.lang.String getRowKeyVar()
Returns:
the rowKeyVar

setRowKeyVar

public void setRowKeyVar(java.lang.String rowKeyVar)
Parameters:
rowKeyVar - the rowKeyVar to set

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

isRowAvailable

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

setRowIndex

public void setRowIndex(int index)
Overrides:
setRowIndex in class javax.faces.component.UIData

getRowIndex

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

getRowKey

public java.lang.Object getRowKey()
Same as for int index, but for complex model key.

Returns:

setRowKey

public void setRowKey(java.lang.Object key)

setRowKey

public void setRowKey(javax.faces.context.FacesContext faces,
                      java.lang.Object key)
Setup current row by key. Perform same functionality as UIData.setRowIndex(int), but for key object - it may be not only row number in sequence data, but, for example - path to current node in tree.

Parameters:
faces - - current FacesContext
key - new key value.

getRowKeyConverter

public javax.faces.convert.Converter getRowKeyConverter()
Returns:
the rowKeyConverter

setRowKeyConverter

public void setRowKeyConverter(javax.faces.convert.Converter rowKeyConverter)
Parameters:
rowKeyConverter - the rowKeyConverter to set

getAjaxKeys

public java.util.Set<java.lang.Object> getAjaxKeys()
Specified by:
getAjaxKeys in interface org.ajax4jsf.component.AjaxDataEncoder

getAllAjaxKeys

public java.util.Set<java.lang.Object> getAllAjaxKeys()

setAjaxKeys

public void setAjaxKeys(java.util.Set<java.lang.Object> ajaxKeys)
Specified by:
setAjaxKeys in interface org.ajax4jsf.component.AjaxDataEncoder

encodeAjaxChild

public void encodeAjaxChild(javax.faces.context.FacesContext context,
                            java.lang.String path,
                            java.util.Set<java.lang.String> ids,
                            java.util.Set<java.lang.String> renderedAreas)
                     throws java.io.IOException
Specified by:
encodeAjaxChild in interface org.ajax4jsf.component.AjaxChildrenEncoder
Throws:
java.io.IOException

getChildrenRenderer

protected AjaxChildrenRenderer getChildrenRenderer()
getter for simple AjaxChildrenRenderer instance in case of ajax responses. If default renderer not support search of children for encode in ajax response, component will use this instance by default.

Returns:

getEncodedIds

protected java.util.Set<java.lang.String> getEncodedIds()
Returns:
Set of values for clientId's of this component, for wich was invoked "encode" methods.

setupVariable

protected void setupVariable(javax.faces.context.FacesContext faces,
                             javax.faces.model.DataModel localModel,
                             boolean rowSelected)
Setup EL variable for different iteration. Value of row data and component state will be put into request scope attributes with names given by "var" and "varState" bean properties. Changed: does not check for row availability now

Parameters:
faces - current faces context
localModel -
rowSelected -

resetDataModel

protected void resetDataModel()
Reset data model. this method must be called twice per request - before decode phase and before component encoding.


setExtendedDataModel

protected void setExtendedDataModel(org.ajax4jsf.model.ExtendedDataModel model)
Set data model. Model value will be stored in Map with key as current clientId for this component, to keep models between phases for same iteration in case if this component child for other UIData

Parameters:
model -

getExtendedDataModel

protected org.ajax4jsf.model.ExtendedDataModel getExtendedDataModel()
Get current data model, or create it by createDataModel() method. For different iterations in ancestor UIData ( if present ) will be returned different models.

Returns:
current data model.

createDataModel

protected abstract org.ajax4jsf.model.ExtendedDataModel createDataModel()
Hook mathod for create data model in concrete implementations.

Returns:

setComponentState

public void setComponentState(org.ajax4jsf.model.DataComponentState state)
Set current state ( at most cases, visual representation ) of this component. Same as for DataModel, component will keep states for different iterations.

Parameters:
state -

getComponentState

public org.ajax4jsf.model.DataComponentState getComponentState()
Returns:
current state of this component.

createComponentState

protected abstract org.ajax4jsf.model.DataComponentState createComponentState()
Hook method for create default state in concrete implementations.

Returns:

getClientId

public java.lang.String getClientId(javax.faces.context.FacesContext faces)
Overrides:
getClientId in class javax.faces.component.UIData

getBaseClientId

public java.lang.String getBaseClientId(javax.faces.context.FacesContext faces)
Get base clietntId of this component ( withowt iteration part )

Parameters:
faces -
Returns:

setId

public void setId(java.lang.String id)
Overrides:
setId in class javax.faces.component.UIComponentBase

captureOrigValue

public void captureOrigValue()
Save current state of data variable.


captureOrigValue

public void captureOrigValue(javax.faces.context.FacesContext faces)
Save current state of data variable.

Parameters:
faces - current faces context

restoreOrigValue

public void restoreOrigValue()
Restore value of data variable after processing phase.


restoreOrigValue

public void restoreOrigValue(javax.faces.context.FacesContext faces)
Restore value of data variable after processing phase.

Parameters:
faces - current faces context

getChildState

protected java.util.Map<java.lang.String,org.ajax4jsf.component.UIDataAdaptor.SavedState> getChildState(javax.faces.context.FacesContext faces)
Parameters:
faces -
Returns:
Saved values of EditableValueHolder fields per iterations.

saveChildState

protected void saveChildState(javax.faces.context.FacesContext faces)
Save values of EditableValueHolder fields before change current row.

Parameters:
faces -

restoreChildState

protected void restoreChildState(javax.faces.context.FacesContext faces)
Restore values of EditableValueHolder fields after change current row.

Parameters:
faces -

keepSaved

protected boolean keepSaved(javax.faces.context.FacesContext context)
Check for validation errors on children components. If true, saved values must be keep on render phase

Parameters:
context -
Returns:

iterate

protected void iterate(javax.faces.context.FacesContext faces,
                       UIDataAdaptor.ComponentVisitor visitor,
                       java.lang.Object argument)
Perform iteration on all children components and all data rows with given visitor.

Parameters:
faces -
visitor -

extractKeySegment

protected java.lang.String extractKeySegment(javax.faces.context.FacesContext context,
                                             java.lang.String tailId)
Extracts segment of component client identifier containing row key

Parameters:
context - current faces context
tailId - substring of component client identifier with base client identifier removed
Returns:
segment containing row key or null

invocableChildren

protected java.util.Iterator<javax.faces.component.UIComponent> invocableChildren()
Returns iterator of components to search through in invokeOnComponent(FacesContext, String, ContextCallback).

Returns:

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

walk

public void walk(javax.faces.context.FacesContext faces,
                 org.ajax4jsf.model.DataVisitor visitor,
                 java.lang.Object argument)
          throws java.io.IOException
Walk ( visit ) this component on all data-avare children for each row.

Parameters:
faces -
visitor -
Throws:
java.io.IOException

processDecodes

protected void processDecodes(javax.faces.context.FacesContext faces,
                              java.lang.Object argument)

processDecodes

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

resetComponent

protected void resetComponent(javax.faces.context.FacesContext faces)
Reset per-request fields in component.

Parameters:
faces -

processUpdates

protected void processUpdates(javax.faces.context.FacesContext faces,
                              java.lang.Object argument)

processUpdates

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

processValidators

protected void processValidators(javax.faces.context.FacesContext faces,
                                 java.lang.Object argument)

processValidators

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

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.IOException
Overrides:
encodeBegin in class javax.faces.component.UIData
Throws:
java.io.IOException

fixedChildren

protected abstract java.util.Iterator<javax.faces.component.UIComponent> fixedChildren()
This method must create iterator for all non-data avare children of this component ( header/footer facets for components and columns in dataTable, facets for tree etc.

Returns:
iterator for all components not sensitive for row data.

dataChildren

protected abstract java.util.Iterator<javax.faces.component.UIComponent> dataChildren()
This method must create iterator for all children components, processed "per row" It can be children of UIColumn in dataTable, nodes in tree

Returns:
iterator for all components processed per row.

addAjaxKeyEvent

protected void addAjaxKeyEvent(javax.faces.event.FacesEvent event)

queueEvent

public void queueEvent(javax.faces.event.FacesEvent event)
Overrides:
queueEvent in class javax.faces.component.UIData

broadcast

public void broadcast(javax.faces.event.FacesEvent event)
               throws javax.faces.event.AbortProcessingException
Overrides:
broadcast in class javax.faces.component.UIData
Throws:
javax.faces.event.AbortProcessingException

broadcastLocal

protected boolean broadcastLocal(javax.faces.event.FacesEvent event)
Process events targetted for concrete implementation. Hook method called from broadcast(FacesEvent)

Parameters:
event - - processed event.
Returns:
true if event processed, false if component must continue processing.

restoreState

public void restoreState(javax.faces.context.FacesContext faces,
                         java.lang.Object object)
Specified by:
restoreState in interface javax.faces.component.StateHolder
Overrides:
restoreState in class javax.faces.component.UIData

saveState

public java.lang.Object saveState(javax.faces.context.FacesContext faces)
Specified by:
saveState in interface javax.faces.component.StateHolder
Overrides:
saveState in class javax.faces.component.UIData

setParent

public void setParent(javax.faces.component.UIComponent parent)
Overrides:
setParent in class javax.faces.component.UIComponentBase

addRequestKey

public void addRequestKey(java.lang.Object key)
Adds argument key to AJAX internal request keys set

Parameters:
key - key to add

removeRequestKey

public void removeRequestKey(java.lang.Object key)
Removes argument key from AJAX internal request keys set

Parameters:
key - key to remove

containsRequestKey

public boolean containsRequestKey(java.lang.Object key)
Checks whether AJAX internal request keys set contains argument key

Parameters:
key - key to check
Returns:
true if set contains key, false - otherwise

clearRequestKeysSet

public void clearRequestKeysSet()
Clears AJAX internal request keys set


getValue

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

setValue

public void setValue(java.lang.Object value)
Overrides:
setValue in class javax.faces.component.UIData

beforeRenderResponse

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


Copyright © 2009. All Rights Reserved.