javax.faces.component
Class UIComponentBase

java.lang.Object
  |
  +--javax.faces.component.UIComponent
        |
        +--javax.faces.component.UIComponentBase
All Implemented Interfaces:
StateHolder
Direct Known Subclasses:
UIColumn, UICommand, UIData, UIForm, UIGraphic, UIMessage, UIMessages, UINamingContainer, UIOutput, UIPanel, UIParameter, UISelectItem, UISelectItems, UIViewRoot

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 its getRendersChildren() method. The default implementation on the Renderer returns false. Subclasses that wish to manage the rendering of their children should override this method to return true instead.


Constructor Summary
UIComponentBase()
           
 
Method Summary
protected  void addFacesListener(javax.faces.event.FacesListener listener)
          Add the specified FacesListener to the set of listeners registered to receive event notifications from this UIComponent.
 void broadcast(javax.faces.event.FacesEvent event)
          Broadcast the specified FacesEvent to all registered event listeners who have expressed an interest in events of this type.
 void decode(javax.faces.context.FacesContext context)
          Decode any new state of this UIComponent from the request contained in the specified FacesContext, and store this state as needed.
 void encodeBegin(javax.faces.context.FacesContext context)
          If our rendered property is true, render the beginning of the current state of this UIComponent to the response contained in the specified FacesContext.
 void encodeChildren(javax.faces.context.FacesContext context)
          If our rendered property is true, render the child UIComponents of this UIComponent.
 void encodeEnd(javax.faces.context.FacesContext context)
          If our rendered property is true, render the ending of the current state of this UIComponent.
 javax.faces.component.UIComponent findComponent(java.lang.String expr)
          Search for and return the UIComponent with an id that matches the specified search expression (if any), according to the algorithm described below.
 java.util.Map getAttributes()
          Return a mutable Map representing the attributes (and properties, see below) associated wth this UIComponent, keyed by attribute name (which must be a String).
 int getChildCount()
          Return the number of child UIComponents that are associated with this UIComponent.
 java.util.List getChildren()
          Return a mutable List representing the child UIComponents associated with this component.
 java.lang.String getClientId(javax.faces.context.FacesContext context)
          Return a client-side identifier for this component, generating one if necessary.
protected  javax.faces.context.FacesContext getFacesContext()
          Convenience method to return the FacesContext instance for the current request.
protected  javax.faces.event.FacesListener[] getFacesListeners(java.lang.Class clazz)
          Return an array of registered FacesListeners that are instances of the specified class.
 javax.faces.component.UIComponent getFacet(java.lang.String name)
          Convenience method to return the named facet, if it exists, or null otherwise.
 java.util.Map getFacets()
          Return a mutable Map representing the facet UIComponents associated with this UIComponent, keyed by facet name (which must be a String).
 java.util.Iterator getFacetsAndChildren()
          Return an Iterator over the facet followed by child UIComponents of this UIComponent.
 java.lang.String getId()
          Return the component identifier of this UIComponent.
 javax.faces.component.UIComponent getParent()
          Return the parent UIComponent of this UIComponent, if any.
protected  javax.faces.render.Renderer getRenderer(javax.faces.context.FacesContext context)
          Convenience method to return the Renderer instance associated with this component, if any; otherwise, return null.
 java.lang.String getRendererType()
          Return the Renderer type for this UIComponent (if any).
 boolean getRendersChildren()
          Return a flag indicating whether this component is responsible for rendering its child components.
 javax.faces.el.ValueBinding getValueBinding(java.lang.String name)
          Return the ValueBinding used to calculate the value for the specified attribute or property name, if any.
 boolean isRendered()
          Return true 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 processDecodes(javax.faces.context.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(javax.faces.context.FacesContext context, java.lang.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.
 java.lang.Object processSaveState(javax.faces.context.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(javax.faces.context.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(javax.faces.context.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(javax.faces.event.FacesEvent event)
          Queue an event for broadcast at the end of the current request processing lifecycle phase.
protected  void removeFacesListener(javax.faces.event.FacesListener listener)
          Remove the specified FacesListener from the set of listeners registered to receive event notifications from this UIComponent.
static java.lang.Object restoreAttachedState(javax.faces.context.FacesContext context, java.lang.Object stateObj)
          This method is called by UIComponent subclasses that need to restore the objects they saved using saveAttachedState(javax.faces.context.FacesContext, java.lang.Object).
 void restoreState(javax.faces.context.FacesContext context, java.lang.Object state)
           Perform any processing required to restore the state from the entries in the state Object.
static java.lang.Object saveAttachedState(javax.faces.context.FacesContext context, java.lang.Object attachedObject)
          This method is called by UIComponent subclasses that want to save one or more attached objects.
 java.lang.Object saveState(javax.faces.context.FacesContext context)
           Gets the state of the instance as a Serializable Object.
 void setId(java.lang.String id)
          Set the component identifier of this UIComponent (if any).
 void setParent(javax.faces.component.UIComponent parent)
          Set the parent UIComponent of this UIComponent.
 void setRendered(boolean rendered)
          Set the rendered property of this UIComponent.
 void setRendererType(java.lang.String rendererType)
          Set the Renderer type for this UIComponent, or null for components that render themselves.
 void setTransient(boolean transientFlag)
          Denotes whether or not the Object implementing this interface must or must not participate in state saving or restoring.
 void setValueBinding(java.lang.String name, javax.faces.el.ValueBinding binding)
          Set the ValueBinding used to calculate the value for the specified attribute or property name, if any.
 
Methods inherited from class javax.faces.component.UIComponent
getFamily
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UIComponentBase

public UIComponentBase()
Method Detail

getAttributes

public java.util.Map getAttributes()
Description copied from class: UIComponent

Return a mutable Map representing the attributes (and properties, see below) associated wth this UIComponent, keyed by attribute name (which must be a String). The returned implementation must support all of the standard and optional Map methods, plus support the following additional requirements:

Specified by:
getAttributes in class UIComponent

getValueBinding

public javax.faces.el.ValueBinding getValueBinding(java.lang.String name)
Description copied from class: UIComponent

Return the ValueBinding used to calculate the value for the specified attribute or property name, if any.

Specified by:
getValueBinding in class UIComponent
Parameters:
name - Name of the attribute or property for which to retrieve a ValueBinding
Throws:
java.lang.NullPointerException - if name is null

setValueBinding

public void setValueBinding(java.lang.String name,
                            javax.faces.el.ValueBinding binding)
Description copied from class: UIComponent

Set the ValueBinding used to calculate the value for the specified attribute or property name, if any.

Specified by:
setValueBinding in class UIComponent
Parameters:
name - Name of the attribute or property for which to set a ValueBinding
binding - The ValueBinding to set, or null to remove any currently set ValueBinding
Throws:
java.lang.IllegalArgumentException - if name is one of id or parent
java.lang.NullPointerException - if name is null

getClientId

public java.lang.String getClientId(javax.faces.context.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 a NamingContainer whose client ID changes (for example, UIData). However, even in these cases, consecutive calls to this method must always return the same value.

Specified by:
getClientId in class UIComponent
Parameters:
context - The FacesContext for the current request
Throws:
java.lang.NullPointerException - if context is null

getId

public java.lang.String getId()
Description copied from class: UIComponent

Return the component identifier of this UIComponent.

Specified by:
getId in class UIComponent

setId

public void setId(java.lang.String id)
Description copied from class: UIComponent

Set the component identifier of this UIComponent (if any). Component identifiers must obey the following syntax restrictions:

Component identifiers must also obey the following semantic restrictions (note that this restriction is NOT enforced by the setId() implementation):

Specified by:
setId in class UIComponent
Parameters:
id - The new component identifier, or null to indicate that this UIComponent does not have a component identifier
Throws:
java.lang.IllegalArgumentException - if id is not syntactically valid
java.lang.IllegalStateException

getParent

public javax.faces.component.UIComponent getParent()
Description copied from class: UIComponent

Return the parent UIComponent of this UIComponent, if any.

Specified by:
getParent in class UIComponent

setParent

public void setParent(javax.faces.component.UIComponent parent)
Description copied from class: UIComponent

Set the parent UIComponent of this UIComponent. 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 child List or facet Map.

Specified by:
setParent in class UIComponent
Parameters:
parent - The new parent, or null 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 class UIComponent

setRendered

public void setRendered(boolean rendered)
Description copied from class: UIComponent

Set the rendered property of this UIComponent.

Specified by:
setRendered in class UIComponent
Parameters:
rendered - If true render this component; otherwise, do not render this component

getRendererType

public java.lang.String getRendererType()
Description copied from class: UIComponent

Return the Renderer type for this UIComponent (if any).

Specified by:
getRendererType in class UIComponent

setRendererType

public void setRendererType(java.lang.String rendererType)
Description copied from class: UIComponent

Set the Renderer type for this UIComponent, or null for components that render themselves.

Specified by:
setRendererType in class UIComponent
Parameters:
rendererType - Logical identifier of the type of Renderer to use, or null 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 calls Renderer.getRendersChildren() and returns the result. If it doesn't, it returns false.

Specified by:
getRendersChildren in class UIComponent

getChildren

public java.util.List getChildren()
Description copied from class: UIComponent

Return a mutable List representing the child UIComponents associated with this component. The returned implementation must support all of the standard and optional List methods, plus support the following additional requirements:

Specified by:
getChildren in class UIComponent

getChildCount

public int getChildCount()
Description copied from class: UIComponent

Return the number of child UIComponents that are associated with this UIComponent. 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 class UIComponent

findComponent

public javax.faces.component.UIComponent findComponent(java.lang.String expr)
Description copied from class: UIComponent

Search for and return the UIComponent with an id that matches the specified search expression (if any), according to the algorithm described below.

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 no NamingContainer components in the ancestry of this component, the root component in the tree is treated as if it were a NamingContainer, whether or not its class actually implements the NamingContainer interface.

A search expression consists of either an identifier (which is matched exactly against the id property of a UIComponent, or a series of such identifiers linked by the NamingContainer.SEPARATOR_CHAR character value. The search algorithm operates as follows:

Specified by:
findComponent in class UIComponent
Parameters:
expr - Search expression identifying the UIComponent to be returned
Returns:
the found UIComponent, or null if the component was not found.
Throws:
java.lang.NullPointerException - if expr is null

getFacets

public java.util.Map getFacets()
Description copied from class: UIComponent

Return a mutable Map representing the facet UIComponents associated with this UIComponent, keyed by facet name (which must be a String). The returned implementation must support all of the standard and optional Map methods, plus support the following additional requirements:

Specified by:
getFacets in class UIComponent

getFacet

public javax.faces.component.UIComponent getFacet(java.lang.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 class UIComponent
Parameters:
name - Name of the desired facet

getFacetsAndChildren

public java.util.Iterator getFacetsAndChildren()
Description copied from class: UIComponent

Return an Iterator over the facet followed by child UIComponents of this UIComponent. 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 empty Iterator is returned.

The returned Iterator must not support the remove() operation.

Specified by:
getFacetsAndChildren in class UIComponent

broadcast

public void broadcast(javax.faces.event.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.

Specified by:
broadcast in class UIComponent
Parameters:
event - The FacesEvent to be broadcast
Throws:
AbortProcessingException - Signal the JavaServer Faces implementation that no further processing on the current event should be performed
java.lang.IllegalStateException
java.lang.NullPointerException - if event is null

decode

public void decode(javax.faces.context.FacesContext context)
Description copied from class: UIComponent

Decode any new state of this UIComponent from the request contained in the specified FacesContext, 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 class UIComponent
Parameters:
context - FacesContext for the request we are processing
Throws:
java.lang.NullPointerException - if context is null

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.IOException
Description copied from class: UIComponent

If our rendered property is true, render the beginning of the current state of this UIComponent to the response contained in the specified FacesContext.

If a Renderer is associated with this UIComponent, the actual encoding will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).

Specified by:
encodeBegin in class UIComponent
Parameters:
context - FacesContext for the response we are creating
Throws:
java.lang.NullPointerException - if context is null
java.io.IOException - if an input/output error occurs while rendering

encodeChildren

public void encodeChildren(javax.faces.context.FacesContext context)
                    throws java.io.IOException
Description copied from class: UIComponent

If our rendered property is true, render the child UIComponents of this UIComponent. This method will only be called if the rendersChildren property is true.

If a Renderer is associated with this UIComponent, the actual encoding will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).

Specified by:
encodeChildren in class UIComponent
Parameters:
context - FacesContext for the response we are creating
Throws:
java.lang.NullPointerException - if context is null
java.io.IOException - if an input/output error occurs while rendering

encodeEnd

public void encodeEnd(javax.faces.context.FacesContext context)
               throws java.io.IOException
Description copied from class: UIComponent

If our rendered property is true, render the ending of the current state of this UIComponent.

If a Renderer is associated with this UIComponent, the actual encoding will be delegated to Renderer.encodeBegin(FacesContext, UIComponent).

Specified by:
encodeEnd in class UIComponent
Parameters:
context - FacesContext for the response we are creating
Throws:
java.lang.NullPointerException - if context is null
java.io.IOException - if an input/output error occurs while rendering

addFacesListener

protected void addFacesListener(javax.faces.event.FacesListener listener)

Add the specified FacesListener to the set of listeners registered to receive event notifications from this UIComponent. It is expected that UIComponent 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 class UIComponent
Parameters:
listener - The FacesListener to be registered
Throws:
java.lang.NullPointerException - if listener is null

getFacesListeners

protected javax.faces.event.FacesListener[] getFacesListeners(java.lang.Class clazz)
Description copied from class: UIComponent

Return an array of registered FacesListeners 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 of clazz.

Specified by:
getFacesListeners in class UIComponent
Parameters:
clazz - Class that must be implemented by a FacesListener for it to be returned
Throws:
java.lang.IllegalArgumentException - if class is not, and does not implement, FacesListener
java.lang.NullPointerException - if clazz is null

removeFacesListener

protected void removeFacesListener(javax.faces.event.FacesListener listener)

Remove the specified FacesListener from the set of listeners registered to receive event notifications from this UIComponent.

Specified by:
removeFacesListener in class UIComponent
Parameters:
listener - The FacesListener to be deregistered
Throws:
java.lang.NullPointerException - if listener is null

queueEvent

public void queueEvent(javax.faces.event.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 the queueEvent() method of the parent UIComponent.

Specified by:
queueEvent in class UIComponent
Parameters:
event - FacesEvent to be queued
Throws:
java.lang.IllegalStateException - if this component is not a descendant of a UIViewRoot
java.lang.NullPointerException - if event is null

processDecodes

public void processDecodes(javax.faces.context.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.

Specified by:
processDecodes in class UIComponent
Parameters:
context - FacesContext for the request we are processing
Throws:
java.lang.NullPointerException - if context is null

processValidators

public void processValidators(javax.faces.context.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.

Specified by:
processValidators in class UIComponent
Parameters:
context - FacesContext for the request we are processing
Throws:
java.lang.NullPointerException - if context is null

processUpdates

public void processUpdates(javax.faces.context.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.

Specified by:
processUpdates in class UIComponent
Parameters:
context - FacesContext for the request we are processing
Throws:
java.lang.NullPointerException - if context is null

processSaveState

public java.lang.Object processSaveState(javax.faces.context.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.

This method may not be called if the state saving method is set to server.

Specified by:
processSaveState in class UIComponent
Parameters:
context - FacesContext for the request we are processing
Throws:
java.lang.NullPointerException - if context is null

processRestoreState

public void processRestoreState(javax.faces.context.FacesContext context,
                                java.lang.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.

This method may not be called if the state saving method is set to server.

Specified by:
processRestoreState in class UIComponent
Parameters:
context - FacesContext for the request we are processing
Throws:
java.lang.NullPointerException - if context is null

getFacesContext

protected javax.faces.context.FacesContext getFacesContext()
Description copied from class: UIComponent

Convenience method to return the FacesContext instance for the current request.

Specified by:
getFacesContext in class UIComponent

getRenderer

protected javax.faces.render.Renderer getRenderer(javax.faces.context.FacesContext context)
Description copied from class: UIComponent

Convenience method to return the Renderer instance associated with this component, if any; otherwise, return null.

Specified by:
getRenderer in class UIComponent
Parameters:
context - FacesContext for the current request

saveState

public java.lang.Object saveState(javax.faces.context.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 the StateHolder.saveState(javax.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 the StateManager

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


restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         java.lang.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 the StateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object) method on all those instances as well.


isTransient

public boolean isTransient()
Description copied from interface: StateHolder

If true, the Object implementing this interface must not participate in state saving or restoring.


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 pass true if this Object will participate in state saving or restoring, otherwise pass false.

saveAttachedState

public static java.lang.Object saveAttachedState(javax.faces.context.FacesContext context,
                                                 java.lang.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 the StateHolder interface. Using this method implies the use of restoreAttachedState(javax.faces.context.FacesContext, java.lang.Object) to restore the attached objects.

This method supports saving attached objects of the following type: Objects, null values, and Lists of these objects. If any contained objects are not Lists and do not implement StateHolder, they must have zero-argument public constructors. The exact structure of the returned object is undefined and opaque, but will be serializable.

Parameters:
context - the FacesContext for this request.
attachedObject - the object, which may be a List instance, or an Object. The attachedObject (or the elements that comprise attachedObject may implement StateHolder.
Throws:
java.lang.NullPointerException - if the context argument is null.

restoreAttachedState

public static java.lang.Object restoreAttachedState(javax.faces.context.FacesContext context,
                                                    java.lang.Object stateObj)
                                             throws java.lang.IllegalStateException

This method is called by UIComponent subclasses that need to restore the objects they saved using saveAttachedState(javax.faces.context.FacesContext, java.lang.Object). This method is tightly coupled with saveAttachedState(javax.faces.context.FacesContext, java.lang.Object).

This method supports restoring all attached objects types supported by saveAttachedState(javax.faces.context.FacesContext, java.lang.Object).

Parameters:
context - the FacesContext for this request
stateObj - the opaque object returned from saveAttachedState(javax.faces.context.FacesContext, java.lang.Object)
Throws:
java.lang.NullPointerException - if context is null.
java.lang.IllegalStateException - if the object is not previously returned by saveAttachedState(javax.faces.context.FacesContext, java.lang.Object).


Copyright ? 2002-2004 Sun Microsystems, Inc. All Rights Reserved.