javax.faces.component

Class UIComponentBase

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

    protected void addFacesListener(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:
    NullPointerException - if listener is null
  • unsubscribeFromEvent

    public void unsubscribeFromEvent(Class<? extends SystemEvent> eventClass,
                                     ComponentSystemEventListener componentListener)

    Remove the listener instance referenced by argument componentListener as a listener for events of type eventClass originating from this specific instance of UIComponent. When doing the comparison to determine if an existing listener is equal to the argument componentListener (and thus must be removed), the equals() method on the existing listener must be invoked, passing the argument componentListener, rather than the other way around.

    Overrides:
    unsubscribeFromEvent in class UIComponent
    Parameters:
    eventClass - the Class of event for which listener must be removed.
    componentListener - the implementation of ComponentSystemEventListener whose ComponentSystemEventListener.processEvent(javax.faces.event.ComponentSystemEvent) method must no longer be called when events of type eventClass are fired.
    Throws:
    NullPointerException - if any of the arguments are null.
    Since:
    2.1
  • 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 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(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 the StateHolder.restoreState(javax.faces.context.FacesContext, java.lang.Object) method on all those instances as well.

    If the state argument is null, take no action and return.

  • 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 not participate in state saving or restoring, otherwise pass false.
  • 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 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 Collections of these objects. If any contained objects are not Collections 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:
    NullPointerException - if the context argument is null.