Class OmniPartialViewContext

  • All Implemented Interfaces:
    FacesWrapper<PartialViewContext>

    public class OmniPartialViewContext
    extends PartialViewContextWrapper

    This OmniFaces partial view context extends and improves the standard partial view context as follows:

    • Support for executing callback scripts by PartialResponseWriter.startEval().
    • Support for adding arguments to an ajax response.
    • Any XML tags which Mojarra and MyFaces has left open after an exception in rendering of an already committed ajax response, will now be properly closed. This prevents errors about malformed XML.
    • Fixes the no-feedback problem when a ViewExpiredException occurs during an ajax request on a page which is restricted by web.xml <security-constraint>. The enduser will now properly be redirected to the login page instead of retrieving an ajax response with only a changed view state (and effectively thus no visual feedback at all).
    You can use the Ajax utility class to easily add callback scripts and arguments.

    This partial view context is already registered by OmniFaces' own faces-config.xml and thus gets auto-initialized when the OmniFaces JAR is bundled in a web application, so end-users do not need to register this partial view context explicitly themselves.

    Since:
    1.2
    Author:
    Bauke Scholtz
    See Also:
    OmniPartialViewContextFactory, FullAjaxExceptionHandler, WebXml, Ajax, Json
    • Constructor Detail

      • OmniPartialViewContext

        public OmniPartialViewContext​(PartialViewContext wrapped)
        Construct a new OmniFaces partial view context around the given wrapped partial view context.
        Parameters:
        wrapped - The wrapped partial view context.
    • Method Detail

      • processPartial

        public void processPartial​(PhaseId phaseId)
        An override which checks if the web.xml security constraint has been triggered during this ajax request (which can happen when the session has been timed out) and if so, then perform a redirect to the originally requested page. Otherwise the enduser ends up with an ajax response containing only the new view state without any form of visual feedback.
        Overrides:
        processPartial in class PartialViewContextWrapper
      • addArgument

        public void addArgument​(String name,
                                Object value)
        Add an argument to the partial response. This is as JSON object available by OmniFaces.Ajax.data. For supported argument value types, read Json.encode(Object). If a given argument type is not supported, then an IllegalArgumentException will be thrown during end of render response.
        Parameters:
        name - The argument name.
        value - The argument value.
      • addCallbackScript

        public void addCallbackScript​(String callbackScript)
        Add a callback script to the partial response. This script will be executed once the partial response is successfully retrieved at the client side.
        Parameters:
        callbackScript - The callback script to be added to the partial response.
      • closePartialResponse

        public void closePartialResponse()
        Close the partial response. If the writer is still in update phase, then end the update and the document. This fixes the Mojarra problem of incomplete ajax responses caused by exceptions during ajax render response.
        See Also:
        FullAjaxExceptionHandler
      • getCurrentInstance

        public static OmniPartialViewContext getCurrentInstance()
        Returns the current instance of the OmniFaces partial view context.
        Returns:
        The current instance of the OmniFaces partial view context.
        Throws:
        IllegalStateException - When there is no current instance of the OmniFaces partial view context. That can happen when the OmniPartialViewContextFactory is not properly registered, or when there's another PartialViewContext implementation which doesn't properly delegate through the wrapped instance.
      • getCurrentInstance

        public static OmniPartialViewContext getCurrentInstance​(FacesContext context)
        Returns the current instance of the OmniFaces partial view context from the given faces context.
        Parameters:
        context - The faces context to obtain the current instance of the OmniFaces partial view context from.
        Returns:
        The current instance of the OmniFaces partial view context from the given faces context.
        Throws:
        IllegalStateException - When there is no current instance of the OmniFaces partial view context. That can happen when the OmniPartialViewContextFactory is not properly registered, or when there's another PartialViewContext implementation which doesn't properly delegate through the wrapped instance.