org.springframework.web.jsf

## Class FacesContextUtils

- java.lang.Object
- - org.springframework.web.jsf.FacesContextUtils

-     public abstract class FacesContextUtils
      extends Object

  Convenience methods to retrieve Spring's root `WebApplicationContext` for a given JSF `FacesContext`. This is useful for accessing a Spring application context from custom JSF-based code.

  Analogous to Spring's WebApplicationContextUtils for the ServletContext.

  Since:
    1.1
  Author:
    Juergen Hoeller
  See Also:
    `ContextLoader`, `WebApplicationContextUtils`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `FacesContextUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static WebApplicationContext` | `getRequiredWebApplicationContext(FacesContext fc)` Find the root `WebApplicationContext` for this web app, typically loaded via ContextLoaderListener.
    `static Object` | `getSessionMutex(FacesContext fc)` Return the best available mutex for the given session: that is, an object to synchronize on for the given session.
    `static WebApplicationContext` | `getWebApplicationContext(FacesContext fc)` Find the root `WebApplicationContext` for this web app, typically loaded via ContextLoaderListener.

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

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

- - ### Constructor Detail

    - #### FacesContextUtils

          public FacesContextUtils()

  - ### Method Detail

    - #### getWebApplicationContext

          public static WebApplicationContext getWebApplicationContext(FacesContext fc)

      Find the root `WebApplicationContext` for this web app, typically loaded via ContextLoaderListener.

      Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

      Parameters:
        `fc` - the FacesContext to find the web application context for
      Returns:
        the root WebApplicationContext for this web app, or `null` if none
      See Also:
        `WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE`

    - #### getRequiredWebApplicationContext

          public static WebApplicationContext getRequiredWebApplicationContext(FacesContext fc)
                                                                        throws IllegalStateException

      Find the root `WebApplicationContext` for this web app, typically loaded via ContextLoaderListener.

      Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

      Parameters:
        `fc` - the FacesContext to find the web application context for
      Returns:
        the root WebApplicationContext for this web app
      Throws:
        `IllegalStateException` - if the root WebApplicationContext could not be found
      See Also:
        `WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE`

    - #### getSessionMutex

          public static Object getSessionMutex(FacesContext fc)

      Return the best available mutex for the given session: that is, an object to synchronize on for the given session.

      Returns the session mutex attribute if available; usually, this means that the HttpSessionMutexListener needs to be defined in `web.xml`. Falls back to the Session reference itself if no mutex attribute found.

      The session mutex is guaranteed to be the same object during the entire lifetime of the session, available under the key defined by the `SESSION_MUTEX_ATTRIBUTE` constant. It serves as a safe reference to synchronize on for locking on the current session.

      In many cases, the Session reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.

      Parameters:
        `fc` - the FacesContext to find the session mutex for
      Returns:
        the mutex object (never `null`)
      See Also:
        `WebUtils.SESSION_MUTEX_ATTRIBUTE`, `HttpSessionMutexListener`