Class PartialRenderListener<T extends javax.faces.component.UIComponent>

  • Type Parameters:
    T - Type of the component for which the listener is registered.
    All Implemented Interfaces:
    IClientIdProviding, IIdChainProviding, EventListener, javax.faces.event.FacesListener, javax.faces.event.SystemEventListener
    Direct Known Subclasses:
    FlowchartRenderer.FlowchartPartialRenderListener

    public abstract class PartialRenderListener<T extends javax.faces.component.UIComponent>
    extends Object
    implements javax.faces.event.SystemEventListener, IIdChainProviding, IClientIdProviding
    Must be registered for a PreRenderViewEvent.

    Normally, during an AJAX request, a component is (re-)rendered by completely replacing a part of the DOM. This is problematic in the case of dynamic interaction components and results in poor UI (flicking etc.). This handler hooks into the PreRenderViewEvent, cancels the scheduled re-render and executes the appropriate JavaScript code that updates the component without completely recreating it.

    Since:
    7.0.0
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • PartialRenderListener

        public PartialRenderListener​(javax.faces.context.FacesContext facesContext,
                                     T component)
        Creates a new partial renderer listener for the given component. This is usually called during the PostAddToViewEvent of a component that wishes to use this listener.
        Parameters:
        facesContext - Current faces context.
        component - The component for which to register this listener.
      • PartialRenderListener

        public PartialRenderListener​(javax.faces.context.FacesContext facesContext,
                                     T component,
                                     boolean ignoreParentUpdates)
        Creates a new partial renderer listener for the given component. This is usually called during the PostAddToViewEvent of a component that wishes to use this listener.
        Parameters:
        facesContext - Current faces context.
        component - The component for which to register this listener.
        ignoreParentUpdates - If true, parent updates are removed.
    • Method Detail

      • isListenerForSource

        public final boolean isListenerForSource​(Object source)
        Specified by:
        isListenerForSource in interface javax.faces.event.SystemEventListener
      • processEvent

        public final void processEvent​(javax.faces.event.SystemEvent event)
                                throws javax.faces.event.AbortProcessingException
        Specified by:
        processEvent in interface javax.faces.event.SystemEventListener
        Throws:
        javax.faces.event.AbortProcessingException
      • encodePartial

        protected abstract void encodePartial​(javax.faces.context.FacesContext context,
                                              T component)
                                       throws Exception
        Performs the actions are necessary for the partial render of the component. Usually this consists of scheduling JavaScript code to be executed on the client (via PrimeFaces.executeInitScript(String).
        Parameters:
        context - The current faces context to use.
        The - component for which this listener was registered.
        Throws:
        Exception - When the data could not be encoded.
      • shouldRenderPartially

        protected boolean shouldRenderPartially​(javax.faces.context.FacesContext context,
                                                T component)
        Parameters:
        context - The current faces context.
        The - component for which this listener was registered.
        Returns:
        true if the component should render partially. The default implementation checks pre-requisites for a partial render to be possible without major issues. Subclasses are encouraged to call this super method, and unconditionally return false if this method returned false.