Class UIViewRoot
- java.lang.Object
-
- jakarta.faces.component.UIComponent
-
- jakarta.faces.component.UIComponentBase
-
- jakarta.faces.component.UIViewRoot
-
- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,UniqueIdVendor,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener
public class UIViewRoot extends UIComponentBase implements UniqueIdVendor
UIViewRoot is the UIComponent that represents the root of the UIComponent tree. This component renders markup as the response to Ajax requests. It also serves as the root of the component tree, and as a place to hang per-view
PhaseListeners.For each of the following lifecycle phase methods:
-
RenderResponse, via
encodeBegin(jakarta.faces.context.FacesContext)andencodeEnd(jakarta.faces.context.FacesContext)
Take the following action regarding
PhaseListeners.Initialize a state flag to
false.If
getBeforePhaseListener()returns non-null, invoke the listener, passing in the correct correspondingPhaseIdfor this phase.Upon return from the listener, call
FacesContext.getResponseComplete()andFacesContext.getRenderResponse(). If either returntrueset the internal state flag totrue.If or one or more listeners have been added by a call to
addPhaseListener(jakarta.faces.event.PhaseListener), invoke thebeforePhasemethod on each one whosePhaseListener.getPhaseId()matches the current phaseId, passing in the samePhaseIdas in the previous step.Upon return from each listener, call
FacesContext.getResponseComplete()andFacesContext.getRenderResponse(). If either returntrueset the internal state flag totrue.Execute any processing for this phase if the internal state flag was not set.
If
getAfterPhaseListener()returns non-null, invoke the listener, passing in the correct correspondingPhaseIdfor this phase.If or one or more listeners have been added by a call to
addPhaseListener(jakarta.faces.event.PhaseListener), invoke theafterPhasemethod on each one whosePhaseListener.getPhaseId()matches the current phaseId, passing in the samePhaseIdas in the previous step.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOMPONENT_FAMILYThe standard component family for this component.static StringCOMPONENT_TYPEThe standard component type for this component.static StringMETADATA_FACET_NAMEThe key in the facet collection that contains the meta data of the view root.static StringUNIQUE_ID_PREFIXThe prefix that will be used for identifiers generated by thecreateUniqueId()method.static StringVIEW_PARAMETERS_KEYThe key in the value set of the view metadata BeanDescriptor, the value of which is aList<.UIViewParameter.Reference>static StringVIEWROOT_PHASE_LISTENER_QUEUES_EXCEPTIONS_PARAM_NAMEIf this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, exceptions thrown byPhaseListeners installed on theUIViewRootare queued to theExceptionHandlerinstead of being logged and swallowed.-
Fields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEY
-
-
Constructor Summary
Constructors Constructor Description UIViewRoot()Create a newUIViewRootinstance with default property values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddComponentResource(FacesContext context, UIComponent componentResource)Add argumentcomponent, which is assumed to represent a resource instance, as a resource to this view.voidaddComponentResource(FacesContext context, UIComponent componentResource, String target)Add argumentcomponent, which is assumed to represent a resource instance, as a resource to this view.voidaddPhaseListener(PhaseListener newPhaseListener)voidbroadcastEvents(FacesContext context, PhaseId phaseId)Broadcast any events that have been queued.StringcreateUniqueId()Generate an identifier for a component.StringcreateUniqueId(FacesContext context, String seed)Generate an identifier for a component.voidencodeBegin(FacesContext context)Override the defaultUIComponentBase.encodeBegin(jakarta.faces.context.FacesContext)behavior.voidencodeChildren(FacesContext context)IfPartialViewContext.isAjaxRequest()returnstrue, perform partial rendering by callingPartialViewContext.processPartial(jakarta.faces.event.PhaseId)withPhaseId.RENDER_RESPONSE.voidencodeEnd(FacesContext context)IfgetAfterPhaseListener()returns non-null, invoke it, passing aPhaseEventfor thePhaseId.RENDER_RESPONSEphase.MethodExpressiongetAfterPhaseListener()Return theMethodExpressionthat will be invoked after this view is rendered.MethodExpressiongetBeforePhaseListener()Return theMethodExpressionthat will be invoked before this view is rendered.List<UIComponent>getComponentResources(FacesContext context)Return an unmodifiable orderedListof allUIComponentresources of all supported targets.List<UIComponent>getComponentResources(FacesContext context, String target)DoctypegetDoctype()Return the doctype of this view.StringgetFamily()Return the identifier of the component family to which this component belongs.LocalegetLocale()Return theLocaleto be used in localizing the response being created for this view.List<PhaseListener>getPhaseListeners()Return an unmodifiable list of thePhaseListenerinstances attached to thisUIViewRootinstance.StringgetRenderKitId()Return the render kit identifier of theRenderKitassociated with this view.booleangetRendersChildren()CallUIComponentBase.getRendersChildren()IfPartialViewContext.isAjaxRequest()returnstruethis method must returntrue.StringgetViewId()Return the view identifier for this view.List<SystemEventListener>getViewListenersForEventClass(Class<? extends SystemEvent> systemEvent)Return theSystemEventListenerinstances registered on thisUIComponentinstance that are interested in events of typeeventClass.Map<String,Object>getViewMap()This implementation simply calls through togetViewMap(boolean), passingtrueas the argument, and returns the result.Map<String,Object>getViewMap(boolean create)Returns aMapthat acts as the interface to the data store that is the "view scope", or, if this instance does not have such aMapand thecreateargument istrue, creates one and returns it.booleanisInView()Override superclass method to always returntruebecause aUIViewRootis defined to always be in a view.voidprocessApplication(FacesContext context)Broadcast any events that have been queued for the Invoke Application phase of the request processing lifecycle and to clear out any events for later phases if the event processing for this phase causedFacesContext.renderResponse()orFacesContext.responseComplete()to be called.voidprocessDecodes(FacesContext context)voidprocessEvent(ComponentSystemEvent event)If the argumenteventis an instance ofPostRestoreStateEventandPartialViewContext.isPartialRequest()returnstrue, then loop over all component resources and callResourceHandler.markResourceRendered(FacesContext, String, String)for each of them.voidprocessRestoreState(FacesContext context, Object state)The default implementation must callUIComponentBase.processRestoreState(jakarta.faces.context.FacesContext, java.lang.Object)from within atryblock.voidprocessUpdates(FacesContext context)voidprocessValidators(FacesContext context)voidqueueEvent(FacesEvent event)Override the defaultUIComponentBase.queueEvent(jakarta.faces.event.FacesEvent)behavior to accumulate the queued events for later broadcasting.voidremoveComponentResource(FacesContext context, UIComponent componentResource)Remove argumentcomponent, which is assumed to represent a resource instance, as a resource to this view.voidremoveComponentResource(FacesContext context, UIComponent componentResource, String target)Remove argumentcomponent, which is assumed to represent a resource instance, as a resource to this view.voidremovePhaseListener(PhaseListener toRemove)If the argumenttoRemoveis in the list ofPhaseListeners for this instance, it must be removed.voidresetValues(FacesContext context, Collection<String> clientIds)Visit the clientIds and, if the component is an instance ofEditableValueHolder, call itsEditableValueHolder.resetValue()method.voidrestoreState(FacesContext context, Object state)Perform any processing required to restore the state from the entries in the state Object.voidrestoreViewScopeState(FacesContext context, Object state)Restore ViewScope state.ObjectsaveState(FacesContext context)Gets the state of the instance as aSerializableObject.voidsetAfterPhaseListener(MethodExpression newAfterPhase)Allow an arbitrary method to be called for the "afterPhase" event as the UIViewRoot runs through its lifecycle.voidsetBeforePhaseListener(MethodExpression newBeforePhase)Allow an arbitrary method to be called for the "beforePhase" event as the UIViewRoot runs through its lifecycle.voidsetDoctype(Doctype doctype)Set the doctype of this view.voidsetInView(boolean isInView)Overridden to take no action.voidsetLocale(Locale locale)Set theLocaleto be used in localizing the response being created for this view.voidsetRenderKitId(String renderKitId)Set the render kit identifier of theRenderKitassociated with this view.voidsetViewId(String viewId)Set the view identifier for this view.voidsubscribeToViewEvent(Class<? extends SystemEvent> systemEvent, SystemEventListener listener)Install the listener instance referenced by argumentlistenerinto theUIViewRootas a listener for events of typesystemEventClass.voidunsubscribeFromViewEvent(Class<? extends SystemEvent> systemEvent, SystemEventListener listener)Remove the listener instance referenced by argumentlistenerfrom theUIViewRootas a listener for events of typesystemEventClass.-
Methods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, invokeOnComponent, isRendered, isTransient, markInitialState, processSaveState, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient, subscribeToEvent, unsubscribeFromEvent
-
Methods inherited from class jakarta.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isVisitable, popComponentFromEL, pushComponentToEL, restoreTransientState, saveTransientState, setValueExpression, visitTree
-
-
-
-
Field Detail
-
METADATA_FACET_NAME
public static final String METADATA_FACET_NAME
The key in the facet collection that contains the meta data of the view root. For example, theUIViewParameters are stored here.- See Also:
- Constant Field Values
-
VIEW_PARAMETERS_KEY
public static final String VIEW_PARAMETERS_KEY
The key in the value set of the view metadata BeanDescriptor, the value of which is a
List<.UIViewParameter.Reference>- Since:
- 2.0
- See Also:
- Constant Field Values
-
COMPONENT_TYPE
public static final String COMPONENT_TYPE
The standard component type for this component.
- See Also:
- Constant Field Values
-
COMPONENT_FAMILY
public static final String COMPONENT_FAMILY
The standard component family for this component.
- See Also:
- Constant Field Values
-
VIEWROOT_PHASE_LISTENER_QUEUES_EXCEPTIONS_PARAM_NAME
public static final String VIEWROOT_PHASE_LISTENER_QUEUES_EXCEPTIONS_PARAM_NAME
If this param is set, and calling toLowerCase().equals("true") on a String representation of its value returns true, exceptions thrown by
PhaseListeners installed on theUIViewRootare queued to theExceptionHandlerinstead of being logged and swallowed.- Since:
- 2.3
- See Also:
- Constant Field Values
-
UNIQUE_ID_PREFIX
public static final String UNIQUE_ID_PREFIX
The prefix that will be used for identifiers generated by the
createUniqueId()method.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UIViewRoot
public UIViewRoot()
Create a new
UIViewRootinstance with default property values.
-
-
Method Detail
-
isInView
public boolean isInView()
Override superclass method to always return
truebecause aUIViewRootis defined to always be in a view.- Overrides:
isInViewin classUIComponent- Returns:
trueif within a view hierarchy,falseotherwise.- Since:
- 2.0
-
setInView
public void setInView(boolean isInView)
Overridden to take no action.
- Overrides:
setInViewin classUIComponent- Parameters:
isInView- ignore the value.- Since:
- 2.0
-
getFamily
public String getFamily()
Description copied from class:UIComponentReturn the identifier of the component family to which this component belongs. This identifier, in conjunction with the value of the
rendererTypeproperty, may be used to select the appropriateRendererfor this component instance. Note this method should NOT returnnull- Specified by:
getFamilyin classUIComponent- Returns:
- the component family (not null).
- See Also:
UIComponent.getFamily()
-
getRenderKitId
public String getRenderKitId()
Return the render kit identifier of the
RenderKitassociated with this view. Unless explicitly set, as inViewHandler.createView(jakarta.faces.context.FacesContext, java.lang.String), the returned value will benull.- Returns:
- the render kit id, or
null.
-
setRenderKitId
public void setRenderKitId(String renderKitId)
Set the render kit identifier of the
RenderKitassociated with this view. This method may be called at any time between the end of Apply Request Values phase of the request processing lifecycle (i.e. when events are being broadcast) and the beginning of the Render Response phase.
-
getViewId
public String getViewId()
Return the view identifier for this view.
- Returns:
- the view id.
-
setViewId
public void setViewId(String viewId)
Set the view identifier for this view.
- Parameters:
viewId- The new view identifier
-
getDoctype
public Doctype getDoctype()
Return the doctype of this view.
- Returns:
- the doctype of this view.
- Since:
- 4.0
-
setDoctype
public void setDoctype(Doctype doctype)
Set the doctype of this view.
- Parameters:
doctype- The doctype.- Since:
- 4.0
-
getBeforePhaseListener
public MethodExpression getBeforePhaseListener()
Return the
MethodExpressionthat will be invoked before this view is rendered.- Returns:
- the
MethodExpressionthat will be invoked before this view is rendered. - Since:
- 1.2
-
setBeforePhaseListener
public void setBeforePhaseListener(MethodExpression newBeforePhase)
Allow an arbitrary method to be called for the "beforePhase" event as the UIViewRoot runs through its lifecycle. This method will be called for all phases except
PhaseId.RESTORE_VIEW. Unlike a truePhaseListener, this approach doesn't allow for only receivingPhaseEvents for a given phase.The method must conform to the signature of
PhaseListener.beforePhase(jakarta.faces.event.PhaseEvent).- Parameters:
newBeforePhase- theMethodExpressionthat will be invoked before this view is rendered.- Since:
- 1.2
-
getAfterPhaseListener
public MethodExpression getAfterPhaseListener()
Return the
MethodExpressionthat will be invoked after this view is rendered.- Returns:
- the
MethodExpressionthat will be invoked after this view is rendered. - Since:
- 1.2
-
setAfterPhaseListener
public void setAfterPhaseListener(MethodExpression newAfterPhase)
Allow an arbitrary method to be called for the "afterPhase" event as the UIViewRoot runs through its lifecycle. This method will be called for all phases including
PhaseId.RESTORE_VIEW. Unlike a truePhaseListener, this approach doesn't allow for only receivingPhaseEvents for a given phase.The method must conform to the signature of
PhaseListener.afterPhase(jakarta.faces.event.PhaseEvent).- Parameters:
newAfterPhase- theMethodExpressionthat will be invoked after this view is rendered.- Since:
- 1.2
-
removePhaseListener
public void removePhaseListener(PhaseListener toRemove)
If the argument
toRemoveis in the list ofPhaseListeners for this instance, it must be removed.- Parameters:
toRemove- thePhaseListenerto remove.- Since:
- 1.2
-
addPhaseListener
public void addPhaseListener(PhaseListener newPhaseListener)
Add the argument
newPhaseListenerto the list ofPhaseListeners on thisUIViewRoot.- Parameters:
newPhaseListener- thePhaseListenerto add- Since:
- 1.2
-
getPhaseListeners
public List<PhaseListener> getPhaseListeners()
Return an unmodifiable list of the
PhaseListenerinstances attached to thisUIViewRootinstance.- Returns:
- the list of phase listeners.
- Since:
- 2.0
-
addComponentResource
public void addComponentResource(FacesContext context, UIComponent componentResource)
Add argument
component, which is assumed to represent a resource instance, as a resource to this view. A resource instance is rendered by a resourceRenderer, as described in the Standard HTML RenderKit. The default implementation must call through toaddComponentResource(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent, java.lang.String).- Parameters:
context-FacesContextfor the current requestcomponentResource- TheUIComponentrepresenting aResourceinstance- Since:
- 2.0
-
addComponentResource
public void addComponentResource(FacesContext context, UIComponent componentResource, String target)
Add argument
component, which is assumed to represent a resource instance, as a resource to this view. A resource instance is rendered by a resourceRenderer, as described in the Standard HTML RenderKit.The
componentmust be added using the following algorithm:-
If the
targetargument isnull, look for atargetattribute on thecomponent. If there is notargetattribute, settargetto be the default valuehead -
Call
getComponentResources(jakarta.faces.context.FacesContext, java.lang.String)to obtain the child list for the given target. -
If the component ID of
componentResourcematches the the ID of a resource that has allready been added, remove the old resource. -
Add the
componentresource to the list.
The resource
Renderermust ensure of the following:- Do not render when
ResourceHandler.isResourceRendered(FacesContext, String, String)returnstrue. - After rendering, call
ResourceHandler.markResourceRendered(FacesContext, String, String).
- Parameters:
context-FacesContextfor the current requestcomponentResource- TheUIComponentrepresenting aResourceinstancetarget- The name of the facet for which theUIComponentwill be added- Since:
- 2.0
-
-
getComponentResources
public List<UIComponent> getComponentResources(FacesContext context, String target)
Return an unmodifiable
ListofUIComponents for the providedtargetagrument. Eachcomponentin theListis assumed to represent a resource instance.The default implementation must use an algorithm equivalent to the the following.
- Locate the facet for the
componentby callinggetFacet()usingtargetas the argument. - If the facet is not found, create the facet by calling
context.getApplication().createComponent().The argument to this method must refer to a component that extendsUIPaneland overrides theencodeAll()method to take no action. This is necessary to prevent component resources from being inadvertently rendered.- Set the
idof the facet to be a string created by prepending the literal string “jakarta_faces_location_” (without the quotes) to the value of thetargetargument - Add the facet to the facets
Mapusingtargetas the key
- Set the
- return the children of the facet
- Parameters:
context- the Faces context.target- The name of the facet for which the components will be returned.- Returns:
- A
ListofUIComponentchildren of the facet with the nametarget. If no children are found for the facet, returnCollections.emptyList(). - Throws:
NullPointerException- iftargetorcontextisnull- Since:
- 2.0
- Locate the facet for the
-
getComponentResources
public List<UIComponent> getComponentResources(FacesContext context)
Return an unmodifiable ordered
Listof allUIComponentresources of all supported targets. Eachcomponentin theListis assumed to represent a resource instance. The ordering is the same as the resources would appear in the component tree.- Parameters:
context- The Faces context.- Returns:
- A
Listof allUIComponentresources of all supported targets. If no resources are found, return an emptyList. - Throws:
NullPointerException- Ifcontextisnull.- Since:
- 2.3
-
removeComponentResource
public void removeComponentResource(FacesContext context, UIComponent componentResource)
Remove argument
component, which is assumed to represent a resource instance, as a resource to this view.- Parameters:
context-FacesContextfor the current requestcomponentResource- TheUIComponentrepresenting aResourceinstance- Since:
- 2.0
-
removeComponentResource
public void removeComponentResource(FacesContext context, UIComponent componentResource, String target)
Remove argument
component, which is assumed to represent a resource instance, as a resource to this view. A resource instance is rendered by a resourceRenderer, as described in the Standard HTML RenderKit.The
componentmust be removed using the following algorithm:- If the
targetargument isnull, look for atargetattribute on thecomponent.
If there is notargetattribute, settargetto be the default valuehead - Call
getComponentResources(jakarta.faces.context.FacesContext, java.lang.String)to obtain the child list for the given target. - Remove the
componentresource from the child list.
- Parameters:
context-FacesContextfor the current requestcomponentResource- TheUIComponentrepresenting aResourceinstancetarget- The name of the facet for which theUIComponentwill be added- Since:
- 2.0
- If the
-
queueEvent
public void queueEvent(FacesEvent event)
Override the default
UIComponentBase.queueEvent(jakarta.faces.event.FacesEvent)behavior to accumulate the queued events for later broadcasting.- Overrides:
queueEventin classUIComponentBase- Parameters:
event-FacesEventto be queued- Throws:
IllegalStateException- if this component is not a descendant of aUIViewRootNullPointerException- ifeventisnull
-
broadcastEvents
public void broadcastEvents(FacesContext context, PhaseId phaseId)
Broadcast any events that have been queued. First broadcast events that have been queued for
PhaseId.ANY_PHASE. Then broadcast ane events that have been queued for the current phase. In both cases,UIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)must be called before the event is broadcast, andUIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)must be called after the return from the broadcast, even in the case of an exception.- Parameters:
context-FacesContextfor the current requestphaseId-PhaseIdof the current phase- Since:
- 2.0
-
processRestoreState
public void processRestoreState(FacesContext context, Object state)
The default implementation must call
UIComponentBase.processRestoreState(jakarta.faces.context.FacesContext, java.lang.Object)from within atryblock. Thetryblock must have afinallyblock that ensures that noFacesEvents remain in the event queue.- Overrides:
processRestoreStatein classUIComponentBase- Parameters:
context- theFacesContextfor this requetsstate- the opaque state object obtained from theStateManager
-
processEvent
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
If the argument
eventis an instance ofPostRestoreStateEventandPartialViewContext.isPartialRequest()returnstrue, then loop over all component resources and callResourceHandler.markResourceRendered(FacesContext, String, String)for each of them. Finally, delegate to super.- Specified by:
processEventin interfaceComponentSystemEventListener- Overrides:
processEventin classUIComponent- Parameters:
event- theComponentSystemEventinstance that is being processed.- Throws:
AbortProcessingException- if lifecycle processing should cease for this request.
-
processDecodes
public void processDecodes(FacesContext context)
Perform partial processing by calling
PartialViewContext.processPartial(jakarta.faces.event.PhaseId)withPhaseId.APPLY_REQUEST_VALUESif:PartialViewContext.isPartialRequest()returnstrueand we don't have a request to process all components in the view (PartialViewContext.isExecuteAll()returnsfalse)
UIComponentBase.processDecodes(jakarta.faces.context.FacesContext)if one of the following conditions are met:PartialViewContext.isPartialRequest()returnstrueand we have a request to process all components in the view (PartialViewContext.isExecuteAll()returnstrue)PartialViewContext.isPartialRequest()returnsfalse
Override the default
UIComponentBase.processDecodes(jakarta.faces.context.FacesContext)behavior to broadcast any queued events after the default processing or partial processing has been completed and to clear out any events for later phases if the event processing for this phase causedFacesContext.renderResponse()orFacesContext.responseComplete()to be called.- Overrides:
processDecodesin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
resetValues
public void resetValues(FacesContext context, Collection<String> clientIds)
Visit the clientIds and, if the component is an instance of
EditableValueHolder, call itsEditableValueHolder.resetValue()method. UseUIComponent.visitTree(jakarta.faces.component.visit.VisitContext, jakarta.faces.component.visit.VisitCallback)to do the visiting.- Parameters:
context- theFacesContextfor the request we are processing.clientIds- The client ids to be visited, on which the described action will be taken.- Since:
- 2.2
-
encodeBegin
public void encodeBegin(FacesContext context) throws IOException
Override the default
UIComponentBase.encodeBegin(jakarta.faces.context.FacesContext)behavior. IfgetBeforePhaseListener()returns non-null, invoke it, passing aPhaseEventfor thePhaseId.RENDER_RESPONSEphase. If the internal list populated by calls toaddPhaseListener(jakarta.faces.event.PhaseListener)is non-empty, any listeners in that list must have theirPhaseListener.beforePhase(jakarta.faces.event.PhaseEvent)method called, passing thePhaseEvent. AnyExceptions that occur during invocation of any of the beforePhase listeners must be logged and swallowed, unless theVIEWROOT_PHASE_LISTENER_QUEUES_EXCEPTIONS_PARAM_NAMEparameter is set. In that case, theExceptionmust be passed to theExceptionHandleras well.- Overrides:
encodeBeginin classUIComponentBase- Parameters:
context-FacesContextfor the response we are creating- Throws:
IOException- if an input/output error occurs while rendering
-
encodeChildren
public void encodeChildren(FacesContext context) throws IOException
If
PartialViewContext.isAjaxRequest()returnstrue, perform partial rendering by callingPartialViewContext.processPartial(jakarta.faces.event.PhaseId)withPhaseId.RENDER_RESPONSE. IfPartialViewContext.isAjaxRequest()returnsfalse, delegate to the parentUIComponentBase.encodeChildren(jakarta.faces.context.FacesContext)method.If this
UIViewRootis an instance ofNamingContainer, then the Jakarta Faces implementation must ensure that all encoded POST request parameter names are prefixed withUIComponent.getContainerClientId(FacesContext)as per rules ofUIComponent.getClientId(FacesContext). This also covers all predefined POST request parameters which are listed below:ResponseStateManager.VIEW_STATE_PARAMResponseStateManager.CLIENT_WINDOW_PARAMResponseStateManager.RENDER_KIT_ID_PARAMClientBehaviorContext.BEHAVIOR_SOURCE_PARAM_NAMEClientBehaviorContext.BEHAVIOR_EVENT_PARAM_NAMEPartialViewContext.PARTIAL_EVENT_PARAM_NAMEPartialViewContext.PARTIAL_EXECUTE_PARAM_NAMEPartialViewContext.PARTIAL_RENDER_PARAM_NAMEPartialViewContext.RESET_VALUES_PARAM_NAME
- Overrides:
encodeChildrenin classUIComponentBase- Parameters:
context-FacesContextfor the response we are creating- Throws:
IOException- if an input/output error occurs while rendering- Since:
- 2.0
-
encodeEnd
public void encodeEnd(FacesContext context) throws IOException
If
getAfterPhaseListener()returns non-null, invoke it, passing aPhaseEventfor thePhaseId.RENDER_RESPONSEphase. AnyExceptions that occur during invocation of the afterPhase listener must be logged and swallowed, unless theVIEWROOT_PHASE_LISTENER_QUEUES_EXCEPTIONS_PARAM_NAMEparameter is set. In that case, theExceptionmust be passed to theExceptionHandleras well.. If the current view has view parameters, as indicated by a non-empty and non-UnsupportedOperationExceptionthrowing return fromViewDeclarationLanguage.getViewMetadata(jakarta.faces.context.FacesContext, String), callUIViewParameter.encodeAll(jakarta.faces.context.FacesContext)on each parameter. If callinggetViewParameters()causesUnsupportedOperationExceptionto be thrown, the exception must be silently swallowed.- Overrides:
encodeEndin classUIComponentBase- Parameters:
context-FacesContextfor the response we are creating- Throws:
IOException- if an input/output error occurs while rendering
-
getRendersChildren
public boolean getRendersChildren()
Call
UIComponentBase.getRendersChildren()IfPartialViewContext.isAjaxRequest()returnstruethis method must returntrue.- Overrides:
getRendersChildrenin classUIComponentBase- Returns:
trueif the component renders its children,falseotherwise.- Since:
- 2.0
-
processValidators
public void processValidators(FacesContext context)
Perform partial processing by calling
PartialViewContext.processPartial(jakarta.faces.event.PhaseId)withPhaseId.PROCESS_VALIDATIONSif:PartialViewContext.isPartialRequest()returnstrueand we don't have a request to process all components in the view (PartialViewContext.isExecuteAll()returnsfalse)
UIComponentBase.processValidators(jakarta.faces.context.FacesContext)if one of the following conditions are met:PartialViewContext.isPartialRequest()returnstrueand we have a request to process all components in the view (PartialViewContext.isExecuteAll()returnstrue)PartialViewContext.isPartialRequest()returnsfalse
Override the default
UIComponentBase.processValidators(jakarta.faces.context.FacesContext)behavior to broadcast any queued events after the default processing or partial processing has been completed and to clear out any events for later phases if the event processing for this phase causedFacesContext.renderResponse()orFacesContext.responseComplete()to be called.- Overrides:
processValidatorsin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull- See Also:
PreValidateEvent,PostValidateEvent
-
processUpdates
public void processUpdates(FacesContext context)
Perform partial processing by calling
PartialViewContext.processPartial(jakarta.faces.event.PhaseId)withPhaseId.UPDATE_MODEL_VALUESif:PartialViewContext.isPartialRequest()returnstrueand we don't have a request to process all components in the view (PartialViewContext.isExecuteAll()returnsfalse)
UIComponentBase.processUpdates(jakarta.faces.context.FacesContext)if one of the following conditions are met:PartialViewContext.isPartialRequest()returnstrueand we have a request to process all components in the view (PartialViewContext.isExecuteAll()returnstrue)PartialViewContext.isPartialRequest()returnsfalse
Override the default
UIComponentBasebehavior to broadcast any queued events after the default processing or partial processing has been completed and to clear out any events for later phases if the event processing for this phase causedFacesContext.renderResponse()orFacesContext.responseComplete()to be called.- Overrides:
processUpdatesin classUIComponentBase- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
processApplication
public void processApplication(FacesContext context)
Broadcast any events that have been queued for the Invoke Application phase of the request processing lifecycle and to clear out any events for later phases if the event processing for this phase caused
FacesContext.renderResponse()orFacesContext.responseComplete()to be called.- Parameters:
context-FacesContextfor the request we are processing- Throws:
NullPointerException- ifcontextisnull
-
createUniqueId
public String createUniqueId()
Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within the non-
NamingContainerchild sub-trees of this UIViewRoot.- Returns:
- the identifier.
-
createUniqueId
public String createUniqueId(FacesContext context, String seed)
Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot. Optionally, a unique seed value can be supplied by component creators which should be included in the generated unique id.
- Specified by:
createUniqueIdin interfaceUniqueIdVendor- Parameters:
context- FacesContextseed- an optional seed value - e.g. based on the position of the component in the VDL-template- Returns:
- a unique-id in this component-container
-
getLocale
public Locale getLocale()
Return the
Localeto be used in localizing the response being created for this view.Algorithm:
If we have a
localeivar, return it. If we have a value expression for "locale", get its value. If the value isnull, return the result of callingViewHandler.calculateLocale(jakarta.faces.context.FacesContext). If the value is an instance ofjava.util.Localereturn it. If the value is a String, convert it to ajava.util.Localeand return it. If there is no value expression for "locale", return the result of callingViewHandler.calculateLocale(jakarta.faces.context.FacesContext).- Returns:
- The current
Localeobtained by executing the above algorithm.
-
setLocale
public void setLocale(Locale locale)
Set the
Localeto be used in localizing the response being created for this view.- Parameters:
locale- The new localization Locale
-
getViewMap
public Map<String,Object> getViewMap()
This implementation simply calls through to
getViewMap(boolean), passingtrueas the argument, and returns the result.- Returns:
- the view map, or
null. - Since:
- 2.0
-
getViewMap
public Map<String,Object> getViewMap(boolean create)
Returns a
Mapthat acts as the interface to the data store that is the "view scope", or, if this instance does not have such aMapand thecreateargument istrue, creates one and returns it. This map must be instantiated lazily and cached for return from subsequent calls to this method on thisUIViewRootinstance.Application.publishEvent(jakarta.faces.context.FacesContext, java.lang.Class<? extends jakarta.faces.event.SystemEvent>, java.lang.Object)must be called, passing the currentFacesContextas the first argument,PostConstructViewMapEvent.classas the second argument,UIViewRoot.classas the third argument and thisUIViewRootinstance as the fourth argument. It is necessary to pass theUIViewRoot.classargument to account for cases when theUIViewRoothas been extended with a custom class.The returned
Mapmust be implemented such that callingclear()on theMapcausesApplication.publishEvent(jakarta.faces.context.FacesContext, java.lang.Class<? extends jakarta.faces.event.SystemEvent>, java.lang.Object)to be called, passingPreDestroyViewMapEvent.classas the first argument and thisUIViewRootinstance as the second argument.Depending upon application configuration, objects stored in the view map may need to be
Serializable. In general, it is a good idea to ensure that any objects stored in the view map areSerializable.For reasons made clear in
ViewScoped, this map must ultimately be stored in the session. For this reason, atruevalue for thecreateargument will force the session to be created with a call toExternalContext.getSession(boolean).See
FacesContext.setViewRoot(jakarta.faces.component.UIViewRoot)for the specification of when theclear()method must be called.- Parameters:
create-trueto create a newMapfor this instance if necessary;falseto returnnullif there's no currentMap.- Returns:
- the view map, or
null. - Since:
- 2.0
-
subscribeToViewEvent
public void subscribeToViewEvent(Class<? extends SystemEvent> systemEvent, SystemEventListener listener)
Install the listener instance referenced by argument
listenerinto theUIViewRootas a listener for events of typesystemEventClass.Note that installed listeners are not maintained as part of the
UIViewRoot's state.- Parameters:
systemEvent- theClassof event for whichlistenermust be fired.listener- the implementation ofSystemEventListenerwhoseSystemEventListener.processEvent(jakarta.faces.event.SystemEvent)method must be called when events of typesystemEventClassare fired.- Throws:
NullPointerException- ifsystemEventClassorlistenerarenull.- Since:
- 2.0
-
unsubscribeFromViewEvent
public void unsubscribeFromViewEvent(Class<? extends SystemEvent> systemEvent, SystemEventListener listener)
Remove the listener instance referenced by argument
listenerfrom theUIViewRootas a listener for events of typesystemEventClass.- Parameters:
systemEvent- theClassof event for whichlistenermust be fired.listener- the implementation ofSystemEventListenerwhoseSystemEventListener.processEvent(jakarta.faces.event.SystemEvent)method must be called when events of typesystemEventClassare fired.- Throws:
NullPointerException- ifsystemEventClassorlistenerarenull.- Since:
- 2.0
-
getViewListenersForEventClass
public List<SystemEventListener> getViewListenersForEventClass(Class<? extends SystemEvent> systemEvent)
Return the
SystemEventListenerinstances registered on thisUIComponentinstance that are interested in events of typeeventClass.- Parameters:
systemEvent- theClassof event for which the listeners must be returned.- Returns:
- Collection of view listeners.
- Throws:
NullPointerException- if argumentsystemEventisnull.- Since:
- 2.0
-
restoreViewScopeState
public void restoreViewScopeState(FacesContext context, Object state)
Restore ViewScope state. This is needed to allow the use of view scoped beans for EL-expressions in the template from which the component tree is built. For example:
<ui:include src="#{viewScopedBean.includeFileName}"/>.- Parameters:
context- current FacesContext.state- the state object.
-
saveState
public Object saveState(FacesContext context)
Description copied from interface:StateHolderGets the state of the instance as a
SerializableObject.If the class that implements this interface has references to instances that implement StateHolder (such as a
UIComponentwith event handlers, validators, etc.) this method must call theStateHolder.saveState(jakarta.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 theStateManagerThis method must not alter the state of the implementing object. In other words, after executing this code:
Object state = component.saveState(facesContext);componentshould be the same as before executing it.The return from this method must be
Serializable- Specified by:
saveStatein interfaceStateHolder- Overrides:
saveStatein classUIComponentBase- Parameters:
context- the Faces context.- Returns:
- the saved state.
-
restoreState
public void restoreState(FacesContext context, Object state)
Description copied from interface:StateHolderPerform 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
UIComponentwith event handlers, validators, etc.) this method must call theStateHolder.restoreState(jakarta.faces.context.FacesContext, java.lang.Object)method on all those instances as well.If the
stateargument isnull, take no action and return.- Specified by:
restoreStatein interfaceStateHolder- Overrides:
restoreStatein classUIComponentBase- Parameters:
context- the Faces context.state- the state.
-
-