org.richfaces.context

## Class ExtendedPartialViewContext

- java.lang.Object
- - javax.faces.context.PartialViewContext
  - - javax.faces.context.PartialViewContextWrapper
    - - org.richfaces.context.ExtendedPartialViewContext

- All Implemented Interfaces:
    javax.faces.FacesWrapper<javax.faces.context.PartialViewContext>

      public class ExtendedPartialViewContext
      extends javax.faces.context.PartialViewContextWrapper

  The RichFaces custom version of PartialViewContext

  Important differences of RichFaces implementation:

  - Values are resolved in runtime by visiting the request activator component and evaluating attributes
  - Usage of extended visit contexts in order to support meta-components processing
  - Support for auto-updateable Ajax components
  - Support for Ajax extensions like passing data to the client, onbeforedomupdate and oncomplete callbacks and `JavaScriptService`

  ## Extended Partial View Processing Scheme

  On following diagram, you can see which classes contributes to RichFaces specific partial view processing (find an explanation bellow):

       +-------------------------+  RF: ExtendedPartialViewContextFactory
       |PartialViewContextFactory|
       +------------+------------+   +------------------------+
                    |                |   PartialViewContext   | Mojarra: PartialViewContextImpl
                    +--------------->|                        | RF: ExtendedPartialViewContext
                      creates        |#processPartial(PhaseId)|
                                     +--+-------------+-------+
                                        |             |
       RF: ExtendedVisitContextFactory  |             |
       +-------------------+            |             |
       |VisitContextFactory|            |             |
       +--------------+----+       uses |             |creates/uses
                      |                 |             |
              creates |                 |             |
                      v                 v             v
              +----------------------------+        +---------------------------+
              |        VisitContext        |        |       VisitCallback       |
              |                            |        |                           |
              |     #invokeVisitContext    |        |          #visit           |
              |(UIComponent, VisitCallback)|        |(VisitContext, UIComponent)|
              +----------------------------+        +---------------------------+
                                                     Mojarra: PhaseAwareVisitCallback
               RF: ExtendedExecuteVisitContext       RF: MetaComponentProcessingVisitCallback
               RF: ExtendedRenderVisitContext        RF: MetaComponentEncodingVisitCallback

                              +-----------------------------+
                              |          UIViewRoot         |
                              |                             |
                              |          #visitTree         |
                              |(VisitContext, VisitCallback)|
                              +-----------------------------+

  `ExtendedPartialViewContext` does (except other things) tracking of the mode (`ExtendedVisitContextMode`). This mode determines whether we are not inside a partial processing phase (inside `processPartial(PhaseId)`) or not (determined by mode equal to `null`).

  The knowledge of current mode is leveraged by `ExtendedVisitContextFactory` that either use visit context created by parent factory (in a wrapper chain) in case the mode is equal to `null` or it creates `ExtendedExecuteVisitContext` (resp. `ExtendedRenderVisitContext`).

  (Note: the `null` mode is necessary because the tree visiting can be leveraged outside of partial tree processing/rendering, e.g. in partial state saving)

  These `VisitContext` wrappers makes sure that when `VisitContext.invokeVisitCallback(UIComponent, VisitCallback)` method is called, the actual `VisitCallback` created by JSF implementation is wrapped in wrappers that allows to execute (resp. render) meta-components `MetaComponentProcessingVisitCallback` (resp. `MetaComponentEncodingVisitCallback`).

  While extended `VisitContext` implementations (`ExtendedRenderVisitContext` and `ExtendedExecuteVisitContext`) allows to visit subtrees that are not normally visited (meta-components and implicitly renderer areas, aka `AjaxOutput`s),

  extended implementations of `VisitCallback` (`MetaComponentProcessingVisitCallback` and `MetaComponentEncodingVisitCallback`) do the extended processing and rendering logic for meta-components.

  `UIViewRoot` is a place where the tree processing starts to dive into subtrees, it is called by JSF implementation of `PartialViewContext.processPartial(PhaseId)`.

  ## Rendering AJAX Extensions

  This context returns wrapped `PartialResponseWriter` in order to intercept its `PartialResponseWriter.endDocument()` method and write extensions before the document is actually ended. For more details see `ExtensionWritingPartialResponseWriter`.

  Author:
    Lukas Fryc, Nick Belaevski

- - ### Field Summary

    - ### Fields inherited from class javax.faces.context.PartialViewContext

      `ALL_PARTIAL_PHASE_CLIENT_IDS, PARTIAL_EXECUTE_PARAM_NAME, PARTIAL_RENDER_PARAM_NAME, RESET_VALUES_PARAM_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExtendedPartialViewContext(javax.faces.context.PartialViewContext wrappedViewContext, javax.faces.context.FacesContext facesContext)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addImplicitExecuteIds(Collection<String> executeIds)` Adding implicitly executed areas to the list of component that should be executed.
    `protected void` | `addImplicitRenderIds(Collection<String> renderIds)` Adding implicitly renderer areas to the list of component that should be rendered.
    `protected void` | `addJavaScriptServicePageScripts(javax.faces.context.FacesContext context)` Add scripts collected by `JavaScriptService` as a partial response extension.
    `void` | `appendOnbeforedomupdate(Object handler)` Append a script to onbeforedomupdate handler
    `void` | `appendOncomplete(Object handler)` Append a script to oncomplete handler
    `protected org.richfaces.context.ExtendedPartialViewContext.ContextMode` | `detectContextMode()` Detects in what context mode should be this partial view request processed
    `Collection<String>` | `getExecuteIds()`
    `protected javax.faces.context.FacesContext` | `getFacesContext()` Returns `FacesContext` for current partial view processing context
    `static ExtendedPartialViewContext` | `getInstance(javax.faces.context.FacesContext facesContext)` Return current `ExtendedPartialViewContext` instance for given `FacesContext`
    `Object` | `getOnbeforedomupdate()` Return onbeforedomupdate handler as an extension for partial-response
    `Object` | `getOncomplete()` Return oncomplete handler as an extension for partial-response
    `javax.faces.context.PartialResponseWriter` | `getPartialResponseWriter()` We are wrapping `PartialResponseWriter` obtained from wrapped implementation into `ExtensionWritingPartialResponseWriter`.
    `Collection<String>` | `getRenderIds()`
    `Map<String,Object>` | `getResponseComponentDataMap()` Returns data provided by components as an extension for partial-response response element
    `Object` | `getResponseData()` Returns user-provided data as an extension for partial-response response element
    `ExtendedVisitContextMode` | `getVisitMode()` Returns in which visit mode we currently operate in
    `javax.faces.context.PartialViewContext` | `getWrapped()`
    `protected void` | `initializeContext()` Initializes context:
    `boolean` | `isExecuteAll()`
    `boolean` | `isLimitRender()` Returns true if rendering in current context is limited to components listed in activator's component render attribute.
    `boolean` | `isRenderAll()`
    `void` | `prependOnbeforedomupdate(Object handler)` Prepend an onbeforedomupdate handler with given script
    `void` | `prependOncomplete(Object handler)` Prepend an oncomplete handler with given script
    `void` | `processPartial(javax.faces.event.PhaseId phaseId)` This method detects in which phase we are and setups `ExtendedVisitContextMode` attribute.
    `void` | `release()`
    `protected void` | `renderExtensions(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)` Render RichFaces specific extensions for partial-update such as: beforedumpdate complete render data componentData
    `void` | `setPartialRequest(boolean isPartialRequest)` This method is present in the JSF 2.2 PartialViewContextWrapper, but not in the JSF 2.1.
    `void` | `setRenderAll(boolean renderAll)`
    `void` | `setResponseData(Object responseData)` Sets user-provided data as an extension for partial-response

    - ### Methods inherited from class javax.faces.context.PartialViewContextWrapper

      `isAjaxRequest, isPartialRequest, isResetValues`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExtendedPartialViewContext

          public ExtendedPartialViewContext(javax.faces.context.PartialViewContext wrappedViewContext,
                                    javax.faces.context.FacesContext facesContext)

  - ### Method Detail

    - #### getWrapped

          public javax.faces.context.PartialViewContext getWrapped()

      Specified by:
        `getWrapped` in interface `javax.faces.FacesWrapper<javax.faces.context.PartialViewContext>`
      Overrides:
        `getWrapped` in class `javax.faces.context.PartialViewContextWrapper`

    - #### setPartialRequest

          public void setPartialRequest(boolean isPartialRequest)

      This method is present in the JSF 2.2 PartialViewContextWrapper, but not in the JSF 2.1. Implementing it here so we are still compatible with JSF 2.1.
      Overrides:
        `setPartialRequest` in class `javax.faces.context.PartialViewContextWrapper`

    - #### getFacesContext

          protected javax.faces.context.FacesContext getFacesContext()

      Returns `FacesContext` for current partial view processing context

    - #### getInstance

          public static ExtendedPartialViewContext getInstance(javax.faces.context.FacesContext facesContext)

      Return current `ExtendedPartialViewContext` instance for given `FacesContext`

    - #### processPartial

          public void processPartial(javax.faces.event.PhaseId phaseId)

      This method detects in which phase we are and setups `ExtendedVisitContextMode` attribute.

      Then it delegates to wrapped implementation of `PartialViewContext.processPartial(PhaseId)`.

      The `ExtendedVisitContextMode` attribute is used by `ExtendedVisitContextFactory` to create either `ExtendedExecuteVisitContext` or `ExtendedRenderVisitContext`.

      Overrides:
        `processPartial` in class `javax.faces.context.PartialViewContextWrapper`

    - #### getExecuteIds

          public Collection<String> getExecuteIds()

      Overrides:
        `getExecuteIds` in class `javax.faces.context.PartialViewContextWrapper`

    - #### getRenderIds

          public Collection<String> getRenderIds()

      Overrides:
        `getRenderIds` in class `javax.faces.context.PartialViewContextWrapper`

    - #### isExecuteAll

          public boolean isExecuteAll()

      Overrides:
        `isExecuteAll` in class `javax.faces.context.PartialViewContextWrapper`

    - #### isRenderAll

          public boolean isRenderAll()

      Overrides:
        `isRenderAll` in class `javax.faces.context.PartialViewContextWrapper`

    - #### setRenderAll

          public void setRenderAll(boolean renderAll)

      Overrides:
        `setRenderAll` in class `javax.faces.context.PartialViewContextWrapper`

    - #### getResponseData

          public Object getResponseData()

      Returns user-provided data as an extension for partial-response response element

    - #### getResponseComponentDataMap

          public Map<String,Object> getResponseComponentDataMap()

      Returns data provided by components as an extension for partial-response response element

    - #### setResponseData

          public void setResponseData(Object responseData)

      Sets user-provided data as an extension for partial-response

    - #### appendOncomplete

          public void appendOncomplete(Object handler)

      Append a script to oncomplete handler

    - #### prependOncomplete

          public void prependOncomplete(Object handler)

      Prepend an oncomplete handler with given script

    - #### getOncomplete

          public Object getOncomplete()

      Return oncomplete handler as an extension for partial-response

    - #### appendOnbeforedomupdate

          public void appendOnbeforedomupdate(Object handler)

      Append a script to onbeforedomupdate handler

    - #### prependOnbeforedomupdate

          public void prependOnbeforedomupdate(Object handler)

      Prepend an onbeforedomupdate handler with given script

    - #### getOnbeforedomupdate

          public Object getOnbeforedomupdate()

      Return onbeforedomupdate handler as an extension for partial-response

    - #### isLimitRender

          public boolean isLimitRender()

      Returns true if rendering in current context is limited to components listed in activator's component render attribute.

    - #### getVisitMode

          public ExtendedVisitContextMode getVisitMode()

      Returns in which visit mode we currently operate in

    - #### getPartialResponseWriter

          public javax.faces.context.PartialResponseWriter getPartialResponseWriter()

      We are wrapping `PartialResponseWriter` obtained from wrapped implementation into `ExtensionWritingPartialResponseWriter`. The wrapper makes sure the RichFaces-specific extensions are written into partial-response before the document is ended.
      Overrides:
        `getPartialResponseWriter` in class `javax.faces.context.PartialViewContextWrapper`

    - #### release

          public void release()

      Overrides:
        `release` in class `javax.faces.context.PartialViewContextWrapper`

    - #### addImplicitExecuteIds

          protected void addImplicitExecuteIds(Collection<String> executeIds)

      Adding implicitly executed areas to the list of component that should be executed. This implementation handles just `UIViewRoot.METADATA_FACET_NAME` execution.

    - #### addImplicitRenderIds

          protected void addImplicitRenderIds(Collection<String> renderIds)

      Adding implicitly renderer areas to the list of component that should be rendered.

    - #### addJavaScriptServicePageScripts

          protected void addJavaScriptServicePageScripts(javax.faces.context.FacesContext context)

      Add scripts collected by `JavaScriptService` as a partial response extension.

    - #### renderExtensions

          protected void renderExtensions(javax.faces.context.FacesContext context,
                              javax.faces.component.UIComponent component)
                                   throws IOException

      Render RichFaces specific extensions for partial-update such as:
      - beforedumpdate
      - complete
      - render
      - data
      - componentData
      Throws:
        `IOException`

    - #### detectContextMode

          protected org.richfaces.context.ExtendedPartialViewContext.ContextMode detectContextMode()

      Detects in what context mode should be this partial view request processed

    - #### initializeContext

          protected void initializeContext()

      Initializes context:

      - `contextMode`
      - `activatorComponentId`
      - `behaviorEvent`

Copyright © 2015 JBoss by Red Hat. All Rights Reserved.