Package org.zkoss.zk.ui.http

## Class WebManager

- java.lang.Object
- - org.zkoss.zk.ui.http.WebManager

-     public class WebManager
      extends java.lang.Object

  A bridge between Web server and ZK.

  Each Web application that uses ZK will have an independent instance of `WebManager`.

  Author:
    tomyeh

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `WebManager​(javax.servlet.ServletContext ctx, java.lang.String updateURI)` | Creates the Web manager.
    `WebManager​(javax.servlet.ServletContext ctx, java.lang.String updateURI, java.lang.String resourceURI)` | Creates the Web manager.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `addActivationListener​(javax.servlet.ServletContext ctx, WebManagerActivationListener listener)` | Register a listener to the specified context such that it will be invoked if the corresponding `WebManager` is created.
    `void` | `destroy()` |
    `ClassWebResource` | `getClassWebResource()` | Returns the handler to retrieve resource from class path, under /web.
    `Desktop` | `getDesktop​(Session sess, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String path, boolean autocreate)` | Returns the desktop of the specified request, or null if not found and autocreate is false, or it has been redirect or forward to other page.
    `java.lang.String` | `getResourceURI()` | Returns the URI for ZK resource
    `static Session` | `getSession​(javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest request)` | Returns the session associated with the specified request request.
    `static Session` | `getSession​(javax.servlet.ServletContext ctx, javax.servlet.http.HttpServletRequest request, boolean create)` | Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.
    `java.lang.String` | `getUpdateURI()` | Returns the URI for asynchronous update.
    `WebApp` | `getWebApp()` | Returns the Web application.
    `static WebApp` | `getWebApp​(javax.servlet.ServletContext ctx)` | Returns the Web application of the specified context.
    `static WebApp` | `getWebAppIfAny​(javax.servlet.ServletContext ctx)` | Returns the Web application of the specified context, or null if not available.
    `static WebManager` | `getWebManager​(javax.servlet.ServletContext ctx)` | Returns the Web manager of the specified context.
    `static WebManager` | `getWebManager​(WebApp wapp)` | Returns the Web manager of the specified `WebApp`.
    `static WebManager` | `getWebManagerIfAny​(javax.servlet.ServletContext ctx)` | Returns the Web manager of the give context, or null if not found.
    `static WebManager` | `getWebManagerIfAny​(WebApp wapp)` | Returns the Web manager of the specified `WebApp`, or null if not found.
    `static Page` | `newPage​(UiFactory uf, RequestInfo ri, PageDefinition pagedef, javax.servlet.ServletResponse response, java.lang.String path)` | Creates a page.
    `static Page` | `newPage​(UiFactory uf, RequestInfo ri, Richlet richlet, javax.servlet.ServletResponse response, java.lang.String path)` | Creates a page.
    `static void` | `setDesktop​(javax.servlet.http.HttpServletRequest request, Desktop desktop)` | Sets the desktop to the specified request.

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

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

- - ### Constructor Detail

    - #### WebManager

          public WebManager​(javax.servlet.ServletContext ctx,
                            java.lang.String updateURI)

      Creates the Web manager. It is singleton in a Web application and it is created automatically by `DHtmlLayoutServlet`, so you rarely need to create it manually.
      Since:
        3.6.0

    - #### WebManager

          public WebManager​(javax.servlet.ServletContext ctx,
                            java.lang.String updateURI,
                            java.lang.String resourceURI)

      Creates the Web manager. It is singleton in a Web application and it is created automatically by `DHtmlLayoutServlet`, so you rarely need to create it manually.
      Parameters:
        `ctx` - the servlet context
        `updateURI` - the URI for asynchronous update
        `resourceURI` - the URI for ZK resource.
      Since:
        9.5.0

  - ### Method Detail

    - #### destroy

          public void destroy()

    - #### getClassWebResource

          public final ClassWebResource getClassWebResource()

      Returns the handler to retrieve resource from class path, under /web.

    - #### getUpdateURI

          public java.lang.String getUpdateURI()

      Returns the URI for asynchronous update.

      Notice that the returned URI is not encoded, i.e., it doesn't proceed with the servlet context prefix.

      Since:
        3.6.2
      See Also:
        `Desktop.getUpdateURI(java.lang.String)`, `WebApp.getUpdateURI()`

    - #### getResourceURI

          public java.lang.String getResourceURI()

      Returns the URI for ZK resource

      Notice that the returned URI is not encoded, i.e., it doesn't proceed with the servlet context prefix.

      Since:
        9.5.0
      See Also:
        `Desktop.getResourceURI(java.lang.String)`, `WebApp.getResourceURI()`

    - #### getWebApp

          public final WebApp getWebApp()

      Returns the Web application. Notice: a Web application is allocated for each servlet.

    - #### getWebApp

          public static final WebApp getWebApp​(javax.servlet.ServletContext ctx)

      Returns the Web application of the specified context.
      Throws:
        `UiException` - if not found (i.e., not initialized properly)
      Since:
        5.0.0

    - #### addActivationListener

          public static final void addActivationListener​(javax.servlet.ServletContext ctx,
                                                         WebManagerActivationListener listener)

      Register a listener to the specified context such that it will be invoked if the corresponding `WebManager` is created.

      Note: if the Web manager is created already, `WebManagerActivationListener.didActivate(org.zkoss.zk.ui.http.WebManager)` will be invoked immediately before this method returns.

      Since:
        2.4.0

    - #### getWebManager

          public static final WebManager getWebManager​(javax.servlet.ServletContext ctx)

      Returns the Web manager of the specified context.
      Throws:
        `UiException` - if not found (i.e., not initialized properly)

    - #### getWebManager

          public static final WebManager getWebManager​(WebApp wapp)

      Returns the Web manager of the specified `WebApp`.
      Since:
        3.0.4

    - #### getWebManagerIfAny

          public static final WebManager getWebManagerIfAny​(javax.servlet.ServletContext ctx)

      Returns the Web manager of the give context, or null if not found.
      Since:
        5.0.5

    - #### getWebManagerIfAny

          public static final WebManager getWebManagerIfAny​(WebApp wapp)

      Returns the Web manager of the specified `WebApp`, or null if not found.
      Since:
        5.0.5

    - #### getWebAppIfAny

          public static final WebApp getWebAppIfAny​(javax.servlet.ServletContext ctx)

      Returns the Web application of the specified context, or null if not available.
      Since:
        5.0.3

    - #### getSession

          public static final Session getSession​(javax.servlet.ServletContext ctx,
                                                 javax.servlet.http.HttpServletRequest request)

      Returns the session associated with the specified request request. If the request does not have a session, creates one.

    - #### getSession

          public static final Session getSession​(javax.servlet.ServletContext ctx,
                                                 javax.servlet.http.HttpServletRequest request,
                                                 boolean create)

      Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.
      Parameters:
        `create` - true to create a new session for this request if necessary; false to return null if there's no current session
      Since:
        3.0.1

    - #### getDesktop

          public Desktop getDesktop​(Session sess,
                                    javax.servlet.ServletRequest request,
                                    javax.servlet.ServletResponse response,
                                    java.lang.String path,
                                    boolean autocreate)

      Returns the desktop of the specified request, or null if not found and autocreate is false, or it has been redirect or forward to other page.
      Parameters:
        `path` - the path of the ZUML page.
        `autocreate` - whether to create one if not found
      Since:
        3.0.0

    - #### setDesktop

          public static void setDesktop​(javax.servlet.http.HttpServletRequest request,
                                        Desktop desktop)

      Sets the desktop to the specified request. Used internally for implementation only.

    - #### newPage

          public static Page newPage​(UiFactory uf,
                                     RequestInfo ri,
                                     PageDefinition pagedef,
                                     javax.servlet.ServletResponse response,
                                     java.lang.String path)

      Creates a page. It invokes `UiFactory.newPage(org.zkoss.zk.ui.sys.RequestInfo, org.zkoss.zk.ui.metainfo.PageDefinition, java.lang.String)`. However, it prepares `Executions.getCurrent()` for `IdGenerator.nextPageUuid(org.zkoss.zk.ui.Page)`

      Note: Use this method to create a page, rather than invoking `UiFactory.newPage(org.zkoss.zk.ui.sys.RequestInfo, org.zkoss.zk.ui.metainfo.PageDefinition, java.lang.String)` directly.

      Since:
        3.6.0

    - #### newPage

          public static Page newPage​(UiFactory uf,
                                     RequestInfo ri,
                                     Richlet richlet,
                                     javax.servlet.ServletResponse response,
                                     java.lang.String path)

      Creates a page. It invokes `UiFactory.newPage(org.zkoss.zk.ui.sys.RequestInfo, org.zkoss.zk.ui.metainfo.PageDefinition, java.lang.String)`. However, it prepares `Executions.getCurrent()` for `IdGenerator.nextPageUuid(org.zkoss.zk.ui.Page)`

      Note: Use this method to create a page, rather than invoking `UiFactory.newPage(org.zkoss.zk.ui.sys.RequestInfo, org.zkoss.zk.ui.metainfo.PageDefinition, java.lang.String)` directly.

      Since:
        3.6.0