Class UIComponentBase
- java.lang.Object
-
- jakarta.faces.component.UIComponent
-
- jakarta.faces.component.UIComponentBase
-
- All Implemented Interfaces:
PartialStateHolder
,StateHolder
,TransientStateHolder
,ComponentSystemEventListener
,FacesListener
,SystemEventListenerHolder
,EventListener
- Direct Known Subclasses:
UIColumn
,UICommand
,UIData
,UIForm
,UIGraphic
,UIImportConstants
,UIMessage
,UIMessages
,UINamingContainer
,UIOutput
,UIPanel
,UIParameter
,UISelectItem
,UISelectItems
,UIViewAction
,UIViewRoot
,UIWebsocket
public abstract class UIComponentBase extends UIComponent
UIComponentBase is a convenience base class that implements the default concrete behavior of all methods defined by
UIComponent
.By default, this class defines
getRendersChildren()
to find the renderer for this component and call itsgetRendersChildren()
method. The default implementation on theRenderer
returnsfalse
. As of version 1.2 of the Jakarta Faces Specification, component authors are encouraged to returntrue
from this method and rely on the implementation ofencodeChildren(jakarta.faces.context.FacesContext)
in this class and in the Renderer (Renderer.encodeChildren(jakarta.faces.context.FacesContext, T)
). Subclasses that wish to manage the rendering of their children should override this method to returntrue
instead.
-
-
Field Summary
-
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 UIComponentBase()
Default constructor, populates the descriptor map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClientBehavior(String eventName, ClientBehavior behavior)
This is a default implementation ofClientBehaviorHolder.addClientBehavior(java.lang.String, jakarta.faces.component.behavior.ClientBehavior)
.protected void
addFacesListener(FacesListener listener)
Add the specifiedFacesListener
to the set of listeners registered to receive event notifications from thisUIComponent
.void
broadcast(FacesEvent event)
Broadcast the specifiedFacesEvent
to all registered event listeners who have expressed an interest in events of this type.void
clearInitialState()
For each of the attached objects on this instance that implementPartialStateHolder
, callPartialStateHolder.clearInitialState()
on the attached object.void
decode(FacesContext context)
Decode any new state of thisUIComponent
from the request contained in the specifiedFacesContext
, and store this state as needed.void
encodeBegin(FacesContext context)
If ourrendered
property istrue
, render the beginning of the current state of thisUIComponent
to the response contained in the specifiedFacesContext
.void
encodeChildren(FacesContext context)
void
encodeEnd(FacesContext context)
UIComponent
findComponent(String expression)
Search for and return theUIComponent
with anid
that matches the specified search expression (if any), according to the algorithm described below.Map<String,Object>
getAttributes()
Return a mutableMap
representing the attributes (and properties, see below) associated wth thisUIComponent
, keyed by attribute name (which must be a String).int
getChildCount()
Return the number of childUIComponent
s that are associated with thisUIComponent
.List<UIComponent>
getChildren()
Map<String,List<ClientBehavior>>
getClientBehaviors()
This is a default implementation ofClientBehaviorHolder.getClientBehaviors()
.String
getClientId(FacesContext context)
Return a client-side identifier for this component, generating one if necessary.String
getDefaultEventName()
This is a default implementation ofClientBehaviorHolder.getDefaultEventName()
.Collection<String>
getEventNames()
This is a default implementation ofClientBehaviorHolder.getEventNames()
.protected FacesContext
getFacesContext()
Convenience method to return theFacesContext
instance for the current request.protected FacesListener[]
getFacesListeners(Class clazz)
Return an array of registeredFacesListener
s that are instances of the specified class.UIComponent
getFacet(String name)
Convenience method to return the named facet, if it exists, ornull
otherwise.int
getFacetCount()
Return the number of facetUIComponent
s that are associated with thisUIComponent
.Map<String,UIComponent>
getFacets()
Return a mutableMap
representing the facetUIComponent
s associated with thisUIComponent
, keyed by facet name (which must be a String).Iterator<UIComponent>
getFacetsAndChildren()
String
getId()
Return the component identifier of thisUIComponent
.List<SystemEventListener>
getListenersForEventClass(Class<? extends SystemEvent> eventClass)
Return theSystemEventListener
instances registered on thisUIComponent
instance that are interested in events of typeeventClass
.UIComponent
getParent()
Return the parentUIComponent
of thisUIComponent
, if any.Map<String,Object>
getPassThroughAttributes(boolean create)
This method has the same specification asUIComponent.getPassThroughAttributes()
except that it is allowed to returnnull
if and only if the argumentcreate
isfalse
and no pass through attribute data structure exists for this instance.protected Renderer
getRenderer(FacesContext context)
Convenience method to return theRenderer
instance associated with this component, if any; otherwise, returnnull
.String
getRendererType()
Return theRenderer
type for thisUIComponent
(if any).boolean
getRendersChildren()
Return a flag indicating whether this component is responsible for rendering its child components.boolean
invokeOnComponent(FacesContext context, String clientId, ContextCallback callback)
Starting at this component in the View hierarchy, search for a component with aclientId
equal to the argumentclientId
and, if found, call theContextCallback.invokeContextCallback(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
method on the argumentcallback
, passing the currentFacesContext
and the found component as arguments.boolean
isRendered()
Returntrue
if this component (and its children) should be rendered during the Render Response phase of the request processing lifecycle.boolean
isTransient()
If true, the Object implementing this interface must not participate in state saving or restoring.void
markInitialState()
For each of the attached objects on this instance that implementPartialStateHolder
, callPartialStateHolder.markInitialState()
on the attached object.void
processDecodes(FacesContext context)
Perform the component tree processing required by the Apply Request Values phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.void
processRestoreState(FacesContext context, Object state)
Perform the component tree processing required by the Restore View phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.Object
processSaveState(FacesContext context)
Perform the component tree processing required by the state saving portion of the Render Response phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.void
processUpdates(FacesContext context)
Perform the component tree processing required by the Update Model Values phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.void
processValidators(FacesContext context)
Perform the component tree processing required by the Process Validations phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.void
queueEvent(FacesEvent event)
Queue an event for broadcast at the end of the current request processing lifecycle phase.protected void
removeFacesListener(FacesListener listener)
Remove the specifiedFacesListener
from the set of listeners registered to receive event notifications from thisUIComponent
.static Object
restoreAttachedState(FacesContext context, Object stateObj)
This method is called byUIComponent
subclasses that need to restore the objects they saved usingsaveAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
.void
restoreState(FacesContext context, Object state)
Perform any processing required to restore the state from the entries in the state Object.static Object
saveAttachedState(FacesContext context, Object attachedObject)
This method is called byUIComponent
subclasses that want to save one or more attached objects.Object
saveState(FacesContext context)
Gets the state of the instance as aSerializable
Object.void
setId(String id)
Set the component identifier of thisUIComponent
(if any).void
setParent(UIComponent parent)
Set the parentUIComponent
of thisUIComponent
.void
setRendered(boolean rendered)
Set therendered
property of thisUIComponent
.void
setRendererType(String rendererType)
void
setTransient(boolean transientFlag)
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.void
subscribeToEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener)
Install the listener instance referenced by argumentcomponentListener
as a listener for events of typeeventClass
originating from this specific instance ofUIComponent
.void
unsubscribeFromEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener)
Remove the listener instance referenced by argumentcomponentListener
as a listener for events of typeeventClass
originating from this specific instance ofUIComponent
.-
Methods inherited from class jakarta.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getFamily, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
-
-
-
-
Method Detail
-
getAttributes
public Map<String,Object> getAttributes()
Description copied from class:UIComponent
Return a mutable
Map
representing the attributes (and properties, see below) associated wth thisUIComponent
, keyed by attribute name (which must be a String). The returned implementation must support all of the standard and optionalMap
methods, plus support the following additional requirements:- The
Map
implementation must implement thejava.io.Serializable
interface. - Any attempt to add a
null
key or value must throw aNullPointerException
. - Any attempt to add a key that is not a String must throw a
ClassCastException
. - If the attribute name specified as a key matches a property of this
UIComponent
's implementation class, the following methods will have special behavior:containsKey
- Returnfalse
.get()
- If the property is readable, call the getter method and return the returned value (wrapping primitive values in their corresponding wrapper classes); otherwise throwIllegalArgumentException
.put()
- If the property is writeable, call the setter method to set the corresponding value (unwrapping primitive values in their corresponding wrapper classes). If the property is not writeable, or an attempt is made to set a property of primitive type tonull
, throwIllegalArgumentException
.remove
- ThrowIllegalArgumentException
.
- Specified by:
getAttributes
in classUIComponent
- Returns:
- the component attribute map.
- The
-
getPassThroughAttributes
public Map<String,Object> getPassThroughAttributes(boolean create)
Description copied from class:UIComponent
This method has the same specification as
UIComponent.getPassThroughAttributes()
except that it is allowed to returnnull
if and only if the argumentcreate
isfalse
and no pass through attribute data structure exists for this instance. The returnedMap
implementation must support all of the standard and optionalMap
methods, plus support the following additional requirements. The map must be stored in usingUIComponent.getStateHelper()
.The
Map
implementation must implementjava.io.Serializable
.Any attempt to add a
null
key or value must throw aNullPointerException
.Any attempt to add a key that is not a
String
must throw anIllegalArgumentException
.For backward compatibility with components that extend directly from this class, a default implementation is provided that returns the empty map.
- Overrides:
getPassThroughAttributes
in classUIComponent
- Parameters:
create
- iftrue
, a newMap
instance will be created if it does not exist already. Iffalse
, and there is no existingMap
instance, one will not be created andnull
will be returned.- Returns:
- A
Map
instance, ornull
.
-
getClientId
public String getClientId(FacesContext context)
Description copied from class:UIComponent
Return a client-side identifier for this component, generating one if necessary. The associated
Renderer
, if any, will be asked to convert the clientId to a form suitable for transmission to the client.The return from this method must be the same value throughout the lifetime of the instance, unless the
id
property of the component is changed, or the component is placed in aNamingContainer
whose client ID changes (for example,UIData
). However, even in these cases, consecutive calls to this method must always return the same value. The implementation must follow these steps in determining the clientId:Find the closest ancestor to this component in the view hierarchy that implements
NamingContainer
. CallgetContainerClientId()
on it and save the result as theparentId
local variable. CallUIComponent.getId()
on this component and save the result as themyId
local variable. IfmyId
isnull
, callcontext.getViewRoot().createUniqueId()
and assign the result to myId. IfparentId
is non-null
, letmyId
equalparentId +
. CallUINamingContainer.getSeparatorChar(jakarta.faces.context.FacesContext)
+ myIdRenderer.convertClientId(jakarta.faces.context.FacesContext, java.lang.String)
, passingmyId
, and return the result.- Specified by:
getClientId
in classUIComponent
- Parameters:
context
- TheFacesContext
for the current request- Returns:
- the client id.
- Throws:
NullPointerException
- ifcontext
isnull
-
getId
public String getId()
Description copied from class:UIComponent
Return the component identifier of this
UIComponent
.- Specified by:
getId
in classUIComponent
- Returns:
- the component identifier.
-
setId
public void setId(String id)
Description copied from class:UIComponent
Set the component identifier of this
UIComponent
(if any). Component identifiers must obey the following syntax restrictions:- Must not be a zero-length String.
- First character must be a letter or an underscore ('_').
- Subsequent characters must be a letter, a digit, an underscore ('_'), or a dash ('-').
Component identifiers must also obey the following semantic restrictions (note that this restriction is NOT enforced by the
setId()
implementation):- The specified identifier must be unique among all the components (including facets) that are descendents of the
nearest ancestor
UIComponent
that is aNamingContainer
, or within the scope of the entire component tree if there is no such ancestor that is aNamingContainer
.
- Specified by:
setId
in classUIComponent
- Parameters:
id
- The new component identifier, ornull
to indicate that thisUIComponent
does not have a component identifier- Throws:
IllegalArgumentException
- ifid
is not syntactically validIllegalStateException
-
getParent
public UIComponent getParent()
Description copied from class:UIComponent
Return the parent
UIComponent
of thisUIComponent
, if any. A component must allow child components to be added to and removed from the list of children of this component, even though the child component returns null fromgetParent( )
.- Specified by:
getParent
in classUIComponent
- Returns:
- the parent component.
-
setParent
public void setParent(UIComponent parent)
Description copied from class:UIComponent
Set the parent
UIComponent
of thisUIComponent
. Ifparent.isInView()
returnstrue
, calling this method will first cause aPreRemoveFromViewEvent
to be published, for this node, and then the children of this node. Then, once the re-parenting has occurred, aPostAddToViewEvent
will be published as well, first for this node, and then for the node's children, but only if any of the following conditions are true.-
FacesContext.getCurrentPhaseId()
returnsPhaseId.RESTORE_VIEW
and partial state saving is enabled. -
FacesContext.isPostback()
returnsfalse
andFacesContext.getCurrentPhaseId()
returns something other thanPhaseId.RESTORE_VIEW
This method must never be called by developers; a
UIComponent
's internal implementation will call it as components are added to or removed from a parent's childList
or facetMap
.- Specified by:
setParent
in classUIComponent
- Parameters:
parent
- The new parent, ornull
for the root node of a component tree
-
-
isRendered
public boolean isRendered()
Description copied from class:UIComponent
Return
true
if this component (and its children) should be rendered during the Render Response phase of the request processing lifecycle.- Specified by:
isRendered
in classUIComponent
- Returns:
true
if the component should be rendered,false
otherwise.
-
setRendered
public void setRendered(boolean rendered)
Description copied from class:UIComponent
Set the
rendered
property of thisUIComponent
.- Specified by:
setRendered
in classUIComponent
- Parameters:
rendered
- Iftrue
render this component; otherwise, do not render this component
-
getRendererType
public String getRendererType()
Description copied from class:UIComponent
Return the
Renderer
type for thisUIComponent
(if any).- Specified by:
getRendererType
in classUIComponent
- Returns:
- the renderer type.
-
setRendererType
public void setRendererType(String rendererType)
Description copied from class:UIComponent
Set the
Renderer
type for thisUIComponent
, ornull
for components that render themselves.- Specified by:
setRendererType
in classUIComponent
- Parameters:
rendererType
- Logical identifier of the type ofRenderer
to use, ornull
for components that render themselves
-
getRendersChildren
public boolean getRendersChildren()
Description copied from class:UIComponent
Return a flag indicating whether this component is responsible for rendering its child components. The default implementation in
getRendersChildren()
tries to find the renderer for this component. If it does, it callsRenderer.getRendersChildren()
and returns the result. If it doesn't, it returns false. As of version 1.2 of the Jakarta Faces Specification, component authors are encouraged to returntrue
from this method and rely onencodeChildren(jakarta.faces.context.FacesContext)
.- Specified by:
getRendersChildren
in classUIComponent
- Returns:
true
if the component renders its children,false
otherwise.
-
getChildren
public List<UIComponent> getChildren()
Description copied from class:UIComponent
Return a mutable
List
representing the childUIComponent
s associated with this component. The returned implementation must support all of the standard and optionalList
methods, plus support the following additional requirements:- The
List
implementation must implement thejava.io.Serializable
interface. - Any attempt to add a
null
must throw a NullPointerException - Any attempt to add an object that does not implement
UIComponent
must throw a ClassCastException. - Whenever a new child component is added, the
parent
property of the child must be set to this component instance. If theparent
property of the child was already non-null, the child must first be removed from its previous parent (where it may have been either a child or a facet). - Whenever an existing child component is removed, the
parent
property of the child must be set tonull
. -
After the child component has been added to the view,
Application.publishEvent(jakarta.faces.context.FacesContext, java.lang.Class<? extends jakarta.faces.event.SystemEvent>, java.lang.Object)
must be called, passingPostAddToViewEvent
.class
as the first argument and the newly added component as the second argument if any the following cases are true.-
FacesContext.getCurrentPhaseId()
returnsPhaseId.RESTORE_VIEW
and partial state saving is enabled. -
FacesContext.isPostback()
returnsfalse
andFacesContext.getCurrentPhaseId()
returns something other thanPhaseId.RESTORE_VIEW
-
- Specified by:
getChildren
in classUIComponent
- Returns:
- the list of children.
- The
-
getChildCount
public int getChildCount()
Description copied from class:UIComponent
Return the number of child
UIComponent
s that are associated with thisUIComponent
. If there are no children, this method must return 0. The method must not cause the creation of a child component list.- Specified by:
getChildCount
in classUIComponent
- Returns:
- the number of child components.
-
findComponent
public UIComponent findComponent(String expression)
Description copied from class:UIComponent
Search for and return the
UIComponent
with anid
that matches the specified search expression (if any), according to the algorithm described below.WARNING: The found
UIComponent
instance, if any, is returned without regard for its tree traversal context. Retrieving an Jakarta Expression Language-bound attribute from the component is not safe. Jakarta Expression Language expressions can contain implicit objects, such as#{component}
, which assume they are being evaluated within the scope of a tree traversal context. Evaluating expressions with these kinds of implicit objects outside of a tree traversal context produces undefined results. SeeUIComponent.invokeOnComponent(jakarta.faces.context.FacesContext, java.lang.String, jakarta.faces.component.ContextCallback)
for a method that does correctly account for the tree traversal context when operating on the foundUIComponent
instance.UIComponent.invokeOnComponent(jakarta.faces.context.FacesContext, java.lang.String, jakarta.faces.component.ContextCallback)
is also useful to find components given a simpleclientId
.Component identifiers are required to be unique within the scope of the closest ancestor
NamingContainer
that encloses this component (which might be this component itself). If there are noNamingContainer
components in the ancestry of this component, the root component in the tree is treated as if it were aNamingContainer
, whether or not its class actually implements theNamingContainer
interface.A search expression consists of either an identifier (which is matched exactly against the
id
property of aUIComponent
, or a series of such identifiers linked by theUINamingContainer.getSeparatorChar(jakarta.faces.context.FacesContext)
character value. The search algorithm should operates as follows, though alternate alogrithms may be used as long as the end result is the same:- Identify the
UIComponent
that will be the base for searching, by stopping as soon as one of the following conditions is met:- If the search expression begins with the the separator character (called an "absolute" search expression), the
base will be the root
UIComponent
of the component tree. The leading separator character will be stripped off, and the remainder of the search expression will be treated as a "relative" search expression as described below. - Otherwise, if this
UIComponent
is aNamingContainer
it will serve as the basis. - Otherwise, search up the parents of this component. If a
NamingContainer
is encountered, it will be the base. - Otherwise (if no
NamingContainer
is encountered) the rootUIComponent
will be the base.
- If the search expression begins with the the separator character (called an "absolute" search expression), the
base will be the root
- The search expression (possibly modified in the previous step) is now a "relative" search expression that will be
used to locate the component (if any) that has an
id
that matches, within the scope of the base component. The match is performed as follows:- If the search expression is a simple identifier, this value is compared to the
id
property, and then recursively through the facets and children of the baseUIComponent
(except that if a descendantNamingContainer
is found, its own facets and children are not searched). - If the search expression includes more than one identifier separated by the separator character, the first
identifier is used to locate a
NamingContainer
by the rules in the previous bullet point. Then, thefindComponent()
method of thisNamingContainer
will be called, passing the remainder of the search expression.
- If the search expression is a simple identifier, this value is compared to the
- Specified by:
findComponent
in classUIComponent
- Parameters:
expression
- Search expression identifying theUIComponent
to be returned- Returns:
- the found
UIComponent
, ornull
if the component was not found. - Throws:
NullPointerException
- ifexpr
isnull
- Identify the
-
invokeOnComponent
public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback) throws FacesException
Starting at this component in the View hierarchy, search for a component with a
clientId
equal to the argumentclientId
and, if found, call theContextCallback.invokeContextCallback(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
method on the argumentcallback
, passing the currentFacesContext
and the found component as arguments. This method is similar toUIComponent.findComponent(java.lang.String)
but it does not support the leadingUINamingContainer.getSeparatorChar(jakarta.faces.context.FacesContext)
syntax for searching from the root of the View.The default implementation will first check if
this.getClientId()
is equal to the argumentclientId
. If so, first callUIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
, then call theContextCallback.invokeContextCallback(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
method on the argument callback, passing through theFacesContext
argument and passing this as the component argument. Then callUIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
. If anException
is thrown by the callback, wrap it in aFacesException
and re-throw it. Otherwise, returntrue
.Otherwise, for each component returned by
UIComponent.getFacetsAndChildren()
, callinvokeOnComponent()
passing the arguments to this method, in order. The first timeinvokeOnComponent()
returns true, abort traversing the rest of theIterator
and returntrue
.When calling
ContextCallback.invokeContextCallback(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
the implementation of this method must guarantee that the state of the component passed to the callback correctly reflects the component's position in the View hierarchy with respect to any state found in the argumentclientId
. For example, an iterating component such asUIData
will need to set its row index to correctly reflect the argumentclientId
before finding the appropriate child component backed by the correct row. When the callback returns, either normally or by throwing anException
the implementation of this method must restore the state of the view to the way it was before invoking the callback.If none of the elements from
UIComponent.getFacetsAndChildren()
returnedtrue
frominvokeOnComponent()
, returnfalse
.Simple usage example to find a component by
clientId
.private UIComponent found = null; private void doFind(FacesContext context, String clientId) { context.getViewRoot().invokeOnComponent(context, clientId, new ContextCallback() { public void invokeContextCallback(FacesContext context, UIComponent component) { found = component; } }); }
- Overrides:
invokeOnComponent
in classUIComponent
- Parameters:
context
- theFacesContext
for the current requestclientId
- the client identifier of the component to be passed to the argument callback.callback
- an implementation of the Callback interface.- Returns:
true
if the a component with the givenclientId
is found, the callback method was successfully invoked passing that component as an argument, and no Exception was thrown. Returnsfalse
if no component with the givenclientId
is found.- Throws:
NullPointerException
- if any of the arguments are nullFacesException
- if the argument Callback throws an Exception, it is wrapped in aFacesException
and re-thrown.- Since:
- 1.2
-
getFacets
public Map<String,UIComponent> getFacets()
Description copied from class:UIComponent
Return a mutable
Map
representing the facetUIComponent
s associated with thisUIComponent
, keyed by facet name (which must be a String). The returned implementation must support all of the standard and optionalMap
methods, plus support the following additional requirements:- The
Map
implementation must implement thejava.io.Serializable
interface. - Any attempt to add a
null
key or value must throw a NullPointerException. - Any attempt to add a key that is not a String must throw a ClassCastException.
- Any attempt to add a value that is not a
UIComponent
must throw a ClassCastException. - Whenever a new facet
UIComponent
is added:- The
parent
property of the component must be set to this component instance. - If the
parent
property of the component was already non-null, the component must first be removed from its previous parent (where it may have been either a child or a facet).
- The
- Whenever an existing facet
UIComponent
is removed:- The
parent
property of the facet must be set tonull
.
- The
- Specified by:
getFacets
in classUIComponent
- Returns:
- the map of facets.
- The
-
getFacetCount
public int getFacetCount()
Description copied from class:UIComponent
Return the number of facet
UIComponent
s that are associated with thisUIComponent
. If there are no facets, this method must return 0. The method must not cause the creation of a facet component map.For backwards compatability with classes that extend UIComponent directly, a default implementation is provided that simply calls
UIComponent.getFacets()
and then calls thesize()
method on the returnedMap
. A more optimized version of this method is provided ingetFacetCount()
.- Overrides:
getFacetCount
in classUIComponent
- Returns:
- the number of facets.
-
getFacet
public UIComponent getFacet(String name)
Description copied from class:UIComponent
Convenience method to return the named facet, if it exists, or
null
otherwise. If the requested facet does not exist, the facets Map must not be created.- Specified by:
getFacet
in classUIComponent
- Parameters:
name
- Name of the desired facet- Returns:
- the component, or
null
.
-
getFacetsAndChildren
public Iterator<UIComponent> getFacetsAndChildren()
Description copied from class:UIComponent
Return an
Iterator
over the facet followed by childUIComponent
s of thisUIComponent
. Facets are returned in an undefined order, followed by all the children in the order they are stored in the child list. If this component has no facets or children, an emptyIterator
is returned.The returned
Iterator
must not support theremove()
operation.- Specified by:
getFacetsAndChildren
in classUIComponent
- Returns:
- the facets and children iterator.
-
broadcast
public void broadcast(FacesEvent event) throws AbortProcessingException
Description copied from class:UIComponent
Broadcast the specified
FacesEvent
to all registered event listeners who have expressed an interest in events of this type. Listeners are called in the order in which they were added.If the
event
is an instance ofBehaviorEvent
and the currentcomponent
is the source of theevent
callBehaviorEvent.getBehavior()
to get theBehavior
for the event. CallBehavior.broadcast(jakarta.faces.event.BehaviorEvent)
on theBehavior
instance.- Specified by:
broadcast
in classUIComponent
- Parameters:
event
- TheFacesEvent
to be broadcast- Throws:
AbortProcessingException
- Signal the Jakarta Faces implementation that no further processing on the current event should be performedIllegalStateException
NullPointerException
- ifevent
isnull
-
decode
public void decode(FacesContext context)
Description copied from class:UIComponent
Decode any new state of this
UIComponent
from the request contained in the specifiedFacesContext
, and store this state as needed.During decoding, events may be enqueued for later processing (by event listeners who have registered an interest), by calling
queueEvent()
.- Specified by:
decode
in classUIComponent
- Parameters:
context
-FacesContext
for the request we are processing- Throws:
NullPointerException
- ifcontext
isnull
-
encodeBegin
public void encodeBegin(FacesContext context) throws IOException
Description copied from class:UIComponent
If our
rendered
property istrue
, render the beginning of the current state of thisUIComponent
to the response contained in the specifiedFacesContext
. CallUIComponent.pushComponentToEL(jakarta.faces.context.FacesContext,jakarta.faces.component.UIComponent)
. CallApplication.publishEvent(jakarta.faces.context.FacesContext, java.lang.Class<? extends jakarta.faces.event.SystemEvent>, java.lang.Object)
, passingPreRenderComponentEvent
.class
as the first argument and the component instance to be rendered as the second argument.If a
Renderer
is associated with thisUIComponent
, the actual encoding will be delegated toRenderer.encodeBegin(FacesContext, UIComponent)
.If our
rendered
property isfalse
, callUIComponent.pushComponentToEL(jakarta.faces.context.FacesContext,jakarta.faces.component.UIComponent)
and return immediately.- Specified by:
encodeBegin
in classUIComponent
- Parameters:
context
-FacesContext
for the response we are creating- Throws:
NullPointerException
- ifcontext
isnull
IOException
- if an input/output error occurs while rendering
-
encodeChildren
public void encodeChildren(FacesContext context) throws IOException
Description copied from class:UIComponent
If our
rendered
property istrue
, render the childUIComponent
s of thisUIComponent
. This method will only be called if therendersChildren
property istrue
.If a
Renderer
is associated with thisUIComponent
, the actual encoding will be delegated toRenderer.encodeChildren(FacesContext, UIComponent)
. If noRenderer
is associated with thisUIComponent
, iterate over each of the children of this component and callUIComponent.encodeAll(jakarta.faces.context.FacesContext)
.- Specified by:
encodeChildren
in classUIComponent
- Parameters:
context
-FacesContext
for the response we are creating- Throws:
NullPointerException
- ifcontext
isnull
IOException
- if an input/output error occurs while rendering
-
encodeEnd
public void encodeEnd(FacesContext context) throws IOException
Description copied from class:UIComponent
If our
rendered
property istrue
, render the ending of the current state of thisUIComponent
.If a
Renderer
is associated with thisUIComponent
, the actual encoding will be delegated toRenderer.encodeEnd(FacesContext, UIComponent)
.Call
UIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
. before returning regardless of the value of therendered
property.- Specified by:
encodeEnd
in classUIComponent
- Parameters:
context
-FacesContext
for the response we are creating- Throws:
IOException
- if an input/output error occurs while renderingNullPointerException
- ifcontext
isnull
-
addFacesListener
protected void addFacesListener(FacesListener listener)
Add the specified
FacesListener
to the set of listeners registered to receive event notifications from thisUIComponent
. It is expected thatUIComponent
classes acting as event sources will have corresponding typesafe APIs for registering listeners of the required type, and the implementation of those registration methods will delegate to this method. For example:public class FooEvent extends FacesEvent { ... protected boolean isAppropriateListener(FacesListener listener) { return (listener instanceof FooListener); } protected void processListener(FacesListener listener) { ((FooListener) listener).processFoo(this); } ... } public interface FooListener extends FacesListener { public void processFoo(FooEvent event); } public class FooComponent extends UIComponentBase { ... public void addFooListener(FooListener listener) { addFacesListener(listener); } public void removeFooListener(FooListener listener) { removeFacesListener(listener); } ... }
- Specified by:
addFacesListener
in classUIComponent
- Parameters:
listener
- TheFacesListener
to be registered- Throws:
NullPointerException
- iflistener
isnull
-
getFacesListeners
protected FacesListener[] getFacesListeners(Class clazz)
Description copied from class:UIComponent
Return an array of registered
FacesListener
s that are instances of the specified class. If there are no such registered listeners, a zero-length array is returned. The returned array can be safely be cast to an array strongly typed to an element type ofclazz
.- Specified by:
getFacesListeners
in classUIComponent
- Parameters:
clazz
- Class that must be implemented by aFacesListener
for it to be returned- Returns:
- the Faces listeners, or a zero-length array.
- Throws:
IllegalArgumentException
- ifclass
is not, and does not implement,FacesListener
NullPointerException
- ifclazz
isnull
-
removeFacesListener
protected void removeFacesListener(FacesListener listener)
Remove the specified
FacesListener
from the set of listeners registered to receive event notifications from thisUIComponent
.- Specified by:
removeFacesListener
in classUIComponent
- Parameters:
listener
- TheFacesListener
to be deregistered- Throws:
NullPointerException
- iflistener
isnull
-
queueEvent
public void queueEvent(FacesEvent event)
Description copied from class:UIComponent
Queue an event for broadcast at the end of the current request processing lifecycle phase. The default implementation in
UIComponentBase
must delegate this call to thequeueEvent()
method of the parentUIComponent
.- Specified by:
queueEvent
in classUIComponent
- Parameters:
event
-FacesEvent
to be queued- Throws:
IllegalStateException
- if this component is not a descendant of aUIViewRoot
NullPointerException
- ifevent
isnull
-
subscribeToEvent
public void subscribeToEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener)
Install the listener instance referenced by argument
componentListener
as a listener for events of typeeventClass
originating from this specific instance ofUIComponent
. The default implementation creates an innerSystemEventListener
instance that wraps argumentcomponentListener
as thelistener
argument. This inner class must call through to the argumentcomponentListener
in its implementation ofSystemEventListener.processEvent(jakarta.faces.event.SystemEvent)
and its implementation ofSystemEventListener.isListenerForSource(java.lang.Object)
must return true if the instance class of thisUIComponent
is assignable from the argument toisListenerForSource
.The listener instance referenced by argument
componentListener
may not already be installed as a listener for events of typeeventClass
originating from this specific instance ofUIComponent
. When doing the comparison to determine if an existing listener is equal to the argumentcomponentListener
, theequals()
method on the existing listener must be invoked, passing the argumentcomponentListener
, rather than the other way around.- Overrides:
subscribeToEvent
in classUIComponent
- Parameters:
eventClass
- theClass
of event for whichlistener
must be fired.componentListener
- the implementation ofComponentSystemEventListener
whoseComponentSystemEventListener.processEvent(jakarta.faces.event.ComponentSystemEvent)
method must be called when events of typefacesEventClass
are fired.- Throws:
NullPointerException
- if any of the arguments arenull
.- Since:
- 2.1
-
unsubscribeFromEvent
public void unsubscribeFromEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener)
Remove the listener instance referenced by argument
componentListener
as a listener for events of typeeventClass
originating from this specific instance ofUIComponent
. When doing the comparison to determine if an existing listener is equal to the argumentcomponentListener
(and thus must be removed), theequals()
method on the existing listener must be invoked, passing the argumentcomponentListener
, rather than the other way around.- Overrides:
unsubscribeFromEvent
in classUIComponent
- Parameters:
eventClass
- theClass
of event for whichlistener
must be removed.componentListener
- the implementation ofComponentSystemEventListener
whoseComponentSystemEventListener.processEvent(jakarta.faces.event.ComponentSystemEvent)
method must no longer be called when events of typeeventClass
are fired.- Throws:
NullPointerException
- if any of the arguments arenull
.- Since:
- 2.1
-
getListenersForEventClass
public List<SystemEventListener> getListenersForEventClass(Class<? extends SystemEvent> eventClass)
Return the
SystemEventListener
instances registered on thisUIComponent
instance that are interested in events of typeeventClass
.- Specified by:
getListenersForEventClass
in interfaceSystemEventListenerHolder
- Overrides:
getListenersForEventClass
in classUIComponent
- Parameters:
eventClass
- theClass
of event for which the listeners must be returned.- Returns:
- the list of listeners, never
null
. - Throws:
NullPointerException
- if argumenteventClass
isnull
.- Since:
- 2.1
-
processDecodes
public void processDecodes(FacesContext context)
Description copied from class:UIComponent
Perform the component tree processing required by the Apply Request Values phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.
- If the
rendered
property of thisUIComponent
isfalse
, skip further processing. - Call
UIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
. - Call the
processDecodes()
method of all facets and children of thisUIComponent
, in the order determined by a call togetFacetsAndChildren()
. - Call the
decode()
method of this component. - Call
UIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
from inside of afinally block, just before returning.
- If a
RuntimeException
is thrown during decode processing, callFacesContext.renderResponse()
and re-throw the exception.
- Specified by:
processDecodes
in classUIComponent
- Parameters:
context
-FacesContext
for the request we are processing- Throws:
NullPointerException
- ifcontext
isnull
- If the
-
processValidators
public void processValidators(FacesContext context)
Description copied from class:UIComponent
Perform the component tree processing required by the Process Validations phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.
- If the
rendered
property of thisUIComponent
isfalse
, skip further processing. - Call
UIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
. - Call the
processValidators()
method of all facets and children of thisUIComponent
, in the order determined by a call togetFacetsAndChildren()
. - After returning from calling
getFacetsAndChildren()
callUIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
.
- Specified by:
processValidators
in classUIComponent
- Parameters:
context
-FacesContext
for the request we are processing- Throws:
NullPointerException
- ifcontext
isnull
- See Also:
PreValidateEvent
,PostValidateEvent
- If the
-
processUpdates
public void processUpdates(FacesContext context)
Description copied from class:UIComponent
Perform the component tree processing required by the Update Model Values phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.
- If the
rendered
property of thisUIComponent
isfalse
, skip further processing. - Call
UIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
. - Call the
processUpdates()
method of all facets and children of thisUIComponent
, in the order determined by a call togetFacetsAndChildren()
. After returning from theprocessUpdates()
method on a child or facet, callUIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
- Specified by:
processUpdates
in classUIComponent
- Parameters:
context
-FacesContext
for the request we are processing- Throws:
NullPointerException
- ifcontext
isnull
- If the
-
processSaveState
public Object processSaveState(FacesContext context)
Description copied from class:UIComponent
Perform the component tree processing required by the state saving portion of the Render Response phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.
- consult the
transient
property of this component. If true, just returnnull
. - Call
UIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
. - Call the
processSaveState()
method of all facets and children of thisUIComponent
in the order determined by a call togetFacetsAndChildren()
, skipping children and facets that are transient. Ensure thatUIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
is called correctly after each child or facet. - Call the
saveState()
method of this component. - Encapsulate the child state and your state into a Serializable Object and return it.
This method may not be called if the state saving method is set to server.
- Specified by:
processSaveState
in classUIComponent
- Parameters:
context
-FacesContext
for the request we are processing- Returns:
- the saved state.
- Throws:
NullPointerException
- ifcontext
isnull
- consult the
-
processRestoreState
public void processRestoreState(FacesContext context, Object state)
Description copied from class:UIComponent
Perform the component tree processing required by the Restore View phase of the request processing lifecycle for all facets of this component, all children of this component, and this component itself, as follows.
- Call the
restoreState()
method of this component. - Call
UIComponent.pushComponentToEL(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent)
. - Call the
processRestoreState()
method of all facets and children of thisUIComponent
in the order determined by a call togetFacetsAndChildren()
. After returning from theprocessRestoreState()
method on a child or facet, callUIComponent.popComponentFromEL(jakarta.faces.context.FacesContext)
This method may not be called if the state saving method is set to server.
- Specified by:
processRestoreState
in classUIComponent
- Parameters:
context
-FacesContext
for the request we are processingstate
- the state.- Throws:
NullPointerException
- ifcontext
isnull
- Call the
-
getFacesContext
protected FacesContext getFacesContext()
Description copied from class:UIComponent
Convenience method to return the
FacesContext
instance for the current request.- Specified by:
getFacesContext
in classUIComponent
- Returns:
- the Faces context.
-
getRenderer
protected Renderer getRenderer(FacesContext context)
Description copied from class:UIComponent
Convenience method to return the
Renderer
instance associated with this component, if any; otherwise, returnnull
.- Specified by:
getRenderer
in classUIComponent
- Parameters:
context
-FacesContext
for the current request- Returns:
- the renderer, or
null
.
-
markInitialState
public void markInitialState()
For each of the attached objects on this instance that implement
PartialStateHolder
, callPartialStateHolder.markInitialState()
on the attached object.- Specified by:
markInitialState
in interfacePartialStateHolder
- Overrides:
markInitialState
in classUIComponent
- Since:
- 2.0
-
clearInitialState
public void clearInitialState()
For each of the attached objects on this instance that implement
PartialStateHolder
, callPartialStateHolder.clearInitialState()
on the attached object.- Specified by:
clearInitialState
in interfacePartialStateHolder
- Overrides:
clearInitialState
in classUIComponent
- Since:
- 2.0
-
saveState
public Object saveState(FacesContext context)
Description copied from interface:StateHolder
Gets the state of the instance as a
Serializable
Object.If the class that implements this interface has references to instances that implement StateHolder (such as a
UIComponent
with 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 theStateManager
This method must not alter the state of the implementing object. In other words, after executing this code:
Object state = component.saveState(facesContext);
component
should be the same as before executing it.The return from this method must be
Serializable
- Parameters:
context
- the Faces context.- Returns:
- the saved state.
-
restoreState
public void restoreState(FacesContext context, Object state)
Description copied from interface:StateHolder
Perform 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
UIComponent
with 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
state
argument isnull
, take no action and return.- Parameters:
context
- the Faces context.state
- the state.
-
isTransient
public boolean isTransient()
Description copied from interface:StateHolder
If true, the Object implementing this interface must not participate in state saving or restoring.
- Returns:
true
if transient,false
otherwise.
-
setTransient
public void setTransient(boolean transientFlag)
Description copied from interface:StateHolder
Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.
- Parameters:
transientFlag
- boolean passtrue
if this Object will not participate in state saving or restoring, otherwise passfalse
.
-
saveAttachedState
public static Object saveAttachedState(FacesContext context, Object attachedObject)
This method is called by
UIComponent
subclasses that want to save one or more attached objects. It is a convenience method that does the work of saving attached objects that may or may not implement theStateHolder
interface. Using this method implies the use ofrestoreAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
to restore the attached objects.This method supports saving attached objects of the following type:
Object
s,null
values, andCollection
s of these objects. If any contained objects are notCollection
s and do not implementStateHolder
, they must have zero-argument public constructors. The exact structure of the returned object is undefined and opaque, but will be serializable.- Parameters:
context
- theFacesContext
for this request.attachedObject
- the object, which may be aList
instance, or an Object. TheattachedObject
(or the elements that compriseattachedObject
may implementStateHolder
.- Returns:
- The state object to be saved.
- Throws:
NullPointerException
- if the context argument is null.
-
restoreAttachedState
public static Object restoreAttachedState(FacesContext context, Object stateObj) throws IllegalStateException
This method is called by
UIComponent
subclasses that need to restore the objects they saved usingsaveAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
. This method is tightly coupled withsaveAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
.This method supports restoring all attached objects types supported by
saveAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
.- Parameters:
context
- theFacesContext
for this requeststateObj
- the opaque object returned fromsaveAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
- Returns:
- the object restored from
stateObj
. - Throws:
NullPointerException
- if context is null.IllegalStateException
- if the object is not previously returned bysaveAttachedState(jakarta.faces.context.FacesContext, java.lang.Object)
.
-
addClientBehavior
public void addClientBehavior(String eventName, ClientBehavior behavior)
This is a default implementation of
ClientBehaviorHolder.addClientBehavior(java.lang.String, jakarta.faces.component.behavior.ClientBehavior)
.UIComponent
does not implement theClientBehaviorHolder
interface, but provides default implementations for the methods defined byClientBehaviorHolder
to simplify subclass implementations. Subclasses that wish to support theClientBehaviorHolder
contract must declare that the subclass implementsClientBehaviorHolder
, and must provide an implementation ofClientBehaviorHolder.getEventNames()
.- Parameters:
eventName
- the logical name of the client-side event to attach the behavior to.behavior
- theBehavior
instance to attach for the specified event name.- Since:
- 2.0
-
getEventNames
public Collection<String> getEventNames()
This is a default implementation of
ClientBehaviorHolder.getEventNames()
.UIComponent
does not implement theClientBehaviorHolder
interface, but provides default implementations for the methods defined byClientBehaviorHolder
to simplify subclass implementations. Subclasses that wish to support theClientBehaviorHolder
contract must declare that the subclass implementsClientBehaviorHolder
, and must override this method to return a non-EmptyCollection
of the client event names that the component supports.- Returns:
- the collection of event names.
- Since:
- 2.0
-
getClientBehaviors
public Map<String,List<ClientBehavior>> getClientBehaviors()
This is a default implementation of
ClientBehaviorHolder.getClientBehaviors()
.UIComponent
does not implement theClientBehaviorHolder
interface, but provides default implementations for the methods defined byClientBehaviorHolder
to simplify subclass implementations. Subclasses that wish to support theClientBehaviorHolder
contract must declare that the subclass implementsClientBehaviorHolder
, and must add an implementation ofClientBehaviorHolder.getEventNames()
.- Returns:
- behaviors associated with this component.
- Since:
- 2.0
-
getDefaultEventName
public String getDefaultEventName()
This is a default implementation of
ClientBehaviorHolder.getDefaultEventName()
.UIComponent
does not implement theClientBehaviorHolder
interface, but provides default implementations for the methods defined byClientBehaviorHolder
to simplify subclass implementations. Subclasses that wish to support theClientBehaviorHolder
contract must declare that the subclass implementsClientBehaviorHolder
, and must provide an implementation ofClientBehaviorHolder.getEventNames()
.- Returns:
- the default event name.
-
-