Top Description Inners Fields Constructors Methods
com.sun.faces.context

public Class StateContext

extends Object
Class Inheritance
Static Imports
com.sun.faces.RIConstants.DYNAMIC_CHILD_COUNT, .RIConstants.DYNAMIC_COMPONENT, com.sun.faces.util.ComponentStruct.ADD, .ComponentStruct.REMOVE

Context for dealing with partial state saving mechanics.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract class
public class
StateContext.DynamicAddRemoveListener

A system event listener which is used to listen for changes on the component tree after restore view and before rendering out the view.

public class
public class
StateContext.StatelessAddRemoveListener

An AddRemoveListener that implements the new dynamic component strategy where no state is managed by the listener itself.

Field Summary

Modifier and TypeField and Description
private static final String
private static final Logger
private StateContext.AddRemoveListener
private boolean
private boolean
private ApplicationStateInfo
private boolean
private WeakReference<UIViewRoot>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the component was added after the initial view construction
componentAddedDynamically
(UIComponent
the UIComponent to check
c
)

private StateContext.AddRemoveListener
private int
public List<ComponentStruct>
getDynamicActions()

Get the dynamic list (of adds and removes).

public HashMap<String, UIComponent>

Returns:

the hash map of dynamic components.
getDynamicComponents
()

Get the hash map of dynamic components.

public int
public static StateContext

Returns:

StateContext for this request
getStateContext
(FacesContext
the FacesContext for the current request
ctx
)

public boolean
private int
public boolean

Returns:

true if partial state saving should be used for the specified view ID, otherwise false
isPartialStateSaving
(FacesContext
FacesContext.
ctx
,
String
the view ID to check or null if viewId is unknown.
viewId
)

public static void
release(FacesContext
the Faces context.
facesContext
)

Release the state context.

public void
setTrackViewModifications(boolean
if true and the listener installed by {@link #startTrackViewModifications(javax.faces.context.FacesContext, javax.faces.component.UIViewRoot) is present, then view modifications will be tracked. If false, then modification events will be ignored.
trackMods
)

Toggles the current modification tracking status.

public void
startTrackViewModifications(FacesContext ctx, UIViewRoot root)

Installs a SystemEventListener on the UIViewRoot to track components added to or removed from the view.

public boolean

Returns:

true if view modifications outside of the initial construction of the view are being tracked.
trackViewModifications
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

KEYback to summary
private static final String KEY
LOGGERback to summary
private static final Logger LOGGER
modListenerback to summary
private StateContext.AddRemoveListener modListener
partialback to summary
private boolean partial
partialLockedback to summary
private boolean partialLocked
stateInfoback to summary
private ApplicationStateInfo stateInfo
trackModsback to summary
private boolean trackMods
viewRootRefback to summary
private WeakReference<UIViewRoot> viewRootRef

Constructor Detail

StateContextback to summary
private StateContext(ApplicationStateInfo stateInfo)

Method Detail

componentAddedDynamicallyback to summary
public boolean componentAddedDynamically(UIComponent c)
Parameters
c:UIComponent

the UIComponent to check

Returns:boolean

true if the component was added after the initial view construction

createAddRemoveListenerback to summary
private StateContext.AddRemoveListener createAddRemoveListener(FacesContext context, UIViewRoot root)
decrementDynamicChildCountback to summary
private int decrementDynamicChildCount(FacesContext context, UIComponent parent)
getDynamicActionsback to summary
public List<ComponentStruct> getDynamicActions()

Get the dynamic list (of adds and removes).

getDynamicComponentsback to summary
public HashMap<String, UIComponent> getDynamicComponents()

Get the hash map of dynamic components.

Returns:HashMap<String, UIComponent>

the hash map of dynamic components.

getIndexOfDynamicallyAddedChildInParentback to summary
public int getIndexOfDynamicallyAddedChildInParent(UIComponent c)
getStateContextback to summary
public static StateContext getStateContext(FacesContext ctx)
Parameters
ctx:FacesContext

the FacesContext for the current request

Returns:StateContext

StateContext for this request

hasOneOrMoreDynamicChildback to summary
public boolean hasOneOrMoreDynamicChild(UIComponent parent)
incrementDynamicChildCountback to summary
private int incrementDynamicChildCount(FacesContext context, UIComponent parent)
isPartialStateSavingback to summary
public boolean isPartialStateSaving(FacesContext ctx, String viewId)
Parameters
ctx:FacesContext

FacesContext.

viewId:String

the view ID to check or null if viewId is unknown.

Returns:boolean

true if partial state saving should be used for the specified view ID, otherwise false

releaseback to summary
public static void release(FacesContext facesContext)

Release the state context.

Parameters
facesContext:FacesContext

the Faces context.

setTrackViewModificationsback to summary
public void setTrackViewModifications(boolean trackMods)

Toggles the current modification tracking status.

Parameters
trackMods:boolean

if true and the listener installed by {@link #startTrackViewModifications(javax.faces.context.FacesContext, javax.faces.component.UIViewRoot) is present, then view modifications will be tracked. If false, then modification events will be ignored.

startTrackViewModificationsback to summary
public void startTrackViewModifications(FacesContext ctx, UIViewRoot root)

Installs a SystemEventListener on the UIViewRoot to track components added to or removed from the view.

trackViewModificationsback to summary
public boolean trackViewModifications()
Returns:boolean

true if view modifications outside of the initial construction of the view are being tracked.

com.sun.faces.context back to summary

private abstract Class StateContext.AddRemoveListener

extends Object
implements SystemEventListener
Class Inheritance
All Implemented Interfaces
javax.faces.event.SystemEventListener, javax.faces.event.FacesListener, java.util.EventListener
Known Direct Subclasses
com.sun.faces.context.StateContext.NoopAddRemoveListener, com.sun.faces.context.StateContext.DynamicAddRemoveListener

Field Summary

Modifier and TypeField and Description
private StateContext
stateCtx

Stores the state context we work for,

Constructor Summary

AccessConstructor and Description
protected
AddRemoveListener(FacesContext
the Faces context.
context
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public abstract List<ComponentStruct>

Returns:

the list of adds/removes.
getDynamicActions
()

Get the list of adds/removes.

public abstract HashMap<String, UIComponent>

Returns:

the hash map of dynamic components.
getDynamicComponents
()

Get the hash map of dynamic components.

protected abstract void
handleAdd(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as an ADD.
component
)

Handle the add.

protected abstract void
handleRemove(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as a REMOVE.
component
)

Handle the remove.

public boolean

Returns:

true if the source is OK, false otherwise.
isListenerForSource
(Object
the source object we might be listening for.
source
)

Implements javax.faces.event.SystemEventListener.isListenerForSource.

Are we listening for these particular changes.
public void
processEvent(SystemEvent
the add/remove event.
event
)

Implements javax.faces.event.SystemEventListener.processEvent.

Process the add/remove event.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stateCtxback to summary
private StateContext stateCtx

Stores the state context we work for,

Constructor Detail

AddRemoveListenerback to summary
protected AddRemoveListener(FacesContext context)

Constructor.

Parameters
context:FacesContext

the Faces context.

Method Detail

getDynamicActionsback to summary
public abstract List<ComponentStruct> getDynamicActions()

Get the list of adds/removes.

Returns:List<ComponentStruct>

the list of adds/removes.

getDynamicComponentsback to summary
public abstract HashMap<String, UIComponent> getDynamicComponents()

Get the hash map of dynamic components.

Returns:HashMap<String, UIComponent>

the hash map of dynamic components.

handleAddback to summary
protected abstract void handleAdd(FacesContext context, UIComponent component)

Handle the add.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as an ADD.

handleRemoveback to summary
protected abstract void handleRemove(FacesContext context, UIComponent component)

Handle the remove.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as a REMOVE.

isListenerForSourceback to summary
public boolean isListenerForSource(Object source)

Implements javax.faces.event.SystemEventListener.isListenerForSource.

Are we listening for these particular changes.

Note we are only interested in UIComponent adds/removes that are not the UIViewRoot itself.

Parameters
source:Object

the source object we might be listening for.

Returns:boolean

true if the source is OK, false otherwise.

Annotations
@Override
processEventback to summary
public void processEvent(SystemEvent event) throws AbortProcessingException

Implements javax.faces.event.SystemEventListener.processEvent.

Process the add/remove event.

Parameters
event:SystemEvent

the add/remove event.

Annotations
@Override
Exceptions
AbortProcessingException:
when processing should be aborted.
com.sun.faces.context back to summary

public Class StateContext.DynamicAddRemoveListener

extends AddRemoveListener
Class Inheritance

A system event listener which is used to listen for changes on the component tree after restore view and before rendering out the view.

Field Summary

Modifier and TypeField and Description
private List<ComponentStruct>
dynamicActions

Stores the list of adds/removes.

private transient HashMap<String, UIComponent>
dynamicComponents

Stores the hash map of dynamic components.

Constructor Summary

AccessConstructor and Description
public
DynamicAddRemoveListener(FacesContext
the Faces context.
context
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private String

Returns:

the facet name or null if the component is not the value of a facets map entry.
findFacetNameForComponent
(UIComponent
the component to look for in the facets map entry value.
component
)

Return the facet name for the given component or null if the component is not the value of a facets map entry.

public List<ComponentStruct>

Returns:

the list of adds/removes.
getDynamicActions
()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicActions.

Get the list of adds/removes.
public HashMap<String, UIComponent>

Returns:

the hash map of dynamic components.
getDynamicComponents
()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicComponents.

Get the hash map of dynamic components.
protected void
handleAdd(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as an ADD.
component
)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleAdd.

Handle the add.
private void
handleAddRemoveWithAutoPrune(UIComponent
the UI component.
component
,
ComponentStruct
the dynamic action.
struct
)

Methods that takes care of pruning and adding an action to the dynamic action list.

protected void
handleRemove(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as a REMOVE.
component
)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleRemove.

Handle the remove.
Inherited from com.sun.faces.context.StateContext.AddRemoveListener:
isListenerForSourceprocessEvent

Field Detail

dynamicActionsback to summary
private List<ComponentStruct> dynamicActions

Stores the list of adds/removes.

dynamicComponentsback to summary
private transient HashMap<String, UIComponent> dynamicComponents

Stores the hash map of dynamic components.

Constructor Detail

DynamicAddRemoveListenerback to summary
public DynamicAddRemoveListener(FacesContext context)

Constructor.

Parameters
context:FacesContext

the Faces context.

Method Detail

findFacetNameForComponentback to summary
private String findFacetNameForComponent(UIComponent component)

Return the facet name for the given component or null if the component is not the value of a facets map entry.

Parameters
component:UIComponent

the component to look for in the facets map entry value.

Returns:String

the facet name or null if the component is not the value of a facets map entry.

getDynamicActionsback to summary
public List<ComponentStruct> getDynamicActions()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicActions.

Get the list of adds/removes.

Returns:List<ComponentStruct>

the list of adds/removes.

Annotations
@Override
getDynamicComponentsback to summary
public HashMap<String, UIComponent> getDynamicComponents()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicComponents.

Get the hash map of dynamic components.

Returns:HashMap<String, UIComponent>

the hash map of dynamic components.

Annotations
@Override
handleAddback to summary
protected void handleAdd(FacesContext context, UIComponent component)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleAdd.

Handle the add.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as an ADD.

Annotations
@Override
handleAddRemoveWithAutoPruneback to summary
private void handleAddRemoveWithAutoPrune(UIComponent component, ComponentStruct struct)

Methods that takes care of pruning and adding an action to the dynamic action list.

 If you add a component and the dynamic action list does not contain
 the component yet then add it to the dynamic action list, regardless
 whether or not if was an ADD or REMOVE.
 Else if you add a component and it is already in the dynamic action 
 list and it is the only action for that client id in the dynamic 
 action list then:
  1) If the previous action was an ADD then
     a) If the current action is a REMOVE then remove the component 
        out of the dynamic action list.
     b) If the current action is an ADD then throw a FacesException.
  2) If the previous action was a REMOVE then
     a) If the current action is an ADD then add it to the dynamic
        action list.
     b) If the current action is a REMOVE then throw a FacesException.
 Else if a REMOVE and ADD where captured before then:
  1) If the current action is REMOVE then remove the last dynamic 
     action out of the dynamic action list.
  2) If the current action is ADD then throw a FacesException.
Parameters
component:UIComponent

the UI component.

struct:ComponentStruct

the dynamic action.

handleRemoveback to summary
protected void handleRemove(FacesContext context, UIComponent component)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleRemove.

Handle the remove.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as a REMOVE.

Annotations
@Override
com.sun.faces.context back to summary

public Class StateContext.NoopAddRemoveListener

extends AddRemoveListener
Class Inheritance
Known Direct Subclasses
com.sun.faces.context.StateContext.StatelessAddRemoveListener

Field Summary

Modifier and TypeField and Description
private HashMap<K, V>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public List<ComponentStruct>
public HashMap<String, UIComponent>
getDynamicComponents()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicComponents.

Get the hash map of dynamic components.
protected void
handleAdd(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as an ADD.
component
)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleAdd.

Handle the add.
protected void
handleRemove(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as a REMOVE.
component
)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleRemove.

Handle the remove.
Inherited from com.sun.faces.context.StateContext.AddRemoveListener:
isListenerForSourceprocessEvent

Field Detail

emptyComponentsMapback to summary
private HashMap<K, V> emptyComponentsMap

Constructor Detail

NoopAddRemoveListenerback to summary
public NoopAddRemoveListener(FacesContext context)

Method Detail

getDynamicActionsback to summary
public List<ComponentStruct> getDynamicActions()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicActions.

Doc from com.sun.faces.context.StateContext.AddRemoveListener.getDynamicActions.

Get the list of adds/removes.

Returns:List<ComponentStruct>

the list of adds/removes.

Annotations
@Override
getDynamicComponentsback to summary
public HashMap<String, UIComponent> getDynamicComponents()

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.getDynamicComponents.

Doc from com.sun.faces.context.StateContext.AddRemoveListener.getDynamicComponents.

Get the hash map of dynamic components.

Returns:HashMap<String, UIComponent>

the hash map of dynamic components.

Annotations
@Override
handleAddback to summary
protected void handleAdd(FacesContext context, UIComponent component)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleAdd.

Doc from com.sun.faces.context.StateContext.AddRemoveListener.handleAdd.

Handle the add.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as an ADD.

Annotations
@Override
handleRemoveback to summary
protected void handleRemove(FacesContext context, UIComponent component)

Implements abstract com.sun.faces.context.StateContext.AddRemoveListener.handleRemove.

Doc from com.sun.faces.context.StateContext.AddRemoveListener.handleRemove.

Handle the remove.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as a REMOVE.

Annotations
@Override
com.sun.faces.context back to summary

public Class StateContext.StatelessAddRemoveListener

extends NoopAddRemoveListener
Class Inheritance

An AddRemoveListener that implements the new dynamic component strategy where no state is managed by the listener itself. Instead, we use expando attributes on the dynamic components (and their parents) to track/preserve the dynamic nature of these components.

Field Summary

Modifier and TypeField and Description
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
private void
private Collection<UIComponent>
private Collection<String>
protected void
handleAdd(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as an ADD.
component
)

Overrides com.sun.faces.context.StateContext.NoopAddRemoveListener.handleAdd.

Handle the add.
protected void
handleRemove(FacesContext
the Faces context.
context
,
UIComponent
the UI component to add to the list as a REMOVE.
component
)

Overrides com.sun.faces.context.StateContext.NoopAddRemoveListener.handleRemove.

Handle the remove.
private void
private boolean
private boolean
Inherited from com.sun.faces.context.StateContext.NoopAddRemoveListener:
getDynamicActionsgetDynamicComponents

Field Detail

DYNAMIC_COMPONENT_ADD_COLLECTIONback to summary
private static final String DYNAMIC_COMPONENT_ADD_COLLECTION

Constructor Detail

StatelessAddRemoveListenerback to summary
public StatelessAddRemoveListener(FacesContext context)

Method Detail

childAddedToSameParentAsBeforeback to summary
private boolean childAddedToSameParentAsBefore(UIComponent parent, String childTagId)
childRemovedFromParentback to summary
private void childRemovedFromParent(UIComponent parent, String childTagId)
getDynamicComponentCollectionback to summary
private Collection<UIComponent> getDynamicComponentCollection(Map<Object, Object> contextMap)
getPreviouslyRemovedChildrenback to summary
private Collection<String> getPreviouslyRemovedChildren(UIComponent parent)
handleAddback to summary
protected void handleAdd(FacesContext context, UIComponent component)

Overrides com.sun.faces.context.StateContext.NoopAddRemoveListener.handleAdd.

Doc from com.sun.faces.context.StateContext.AddRemoveListener.handleAdd.

Handle the add.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as an ADD.

Annotations
@Override
handleRemoveback to summary
protected void handleRemove(FacesContext context, UIComponent component)

Overrides com.sun.faces.context.StateContext.NoopAddRemoveListener.handleRemove.

Doc from com.sun.faces.context.StateContext.AddRemoveListener.handleRemove.

Handle the remove.

Parameters
context:FacesContext

the Faces context.

component:UIComponent

the UI component to add to the list as a REMOVE.

Annotations
@Override
markChildrenModifiedback to summary
private void markChildrenModified(UIComponent parent)
thisEventCorrespondsToSubtreeRootAddback to summary
private boolean thisEventCorrespondsToSubtreeRootAdd(FacesContext context, UIComponent c)
thisEventCorrespondsToSubtreeRootRemoveback to summary
private boolean thisEventCorrespondsToSubtreeRootRemove(FacesContext context, UIComponent c)