Interface Desktop

All Superinterfaces:
Scope
All Known Implementing Classes:
DesktopImpl

public interface Desktop extends Scope
Represents a desktop. All pages that is created from the same URL is called a desktop.

A desktop is created automatically when the first page is created during a request.

To access a Page, its desktop must be locked first. Once a desktop is locked to a request, all pages contained in this desktop are free to access.

Author:
tomyeh
  • Method Details

    • getDeviceType

      String getDeviceType()
      Returns the device type that this desktop belongs to.

      A device type identifies the type of a client. For example, "ajax" represents the Web browsers with Ajax support, while "mil" represents clients that supports Mobile Interactive markup Language (on Limited Connected Device, such as mobile phones).

      A desktop can use the languages belonging to the same device type. See also LanguageDefinition.getDeviceType().

      A component can be added to a desktop only if they belong to the same device type.

      Default: depends on the extension of the resource path, "ajax" if the path or extension not available. If Richlet is used, its language definition's device type is assumed.

    • setDeviceType

      void setDeviceType(String deviceType)
      Sets the device type that this desktop belongs to.

      Note: you can change the device type only before any component is attached to a page of the desktop. In other words, you can set the device type only at the initialization stage.

      If the device type is changed, any device allocated for this desktop (getDevice()) will be dropped and recreated at the next invocation to getDevice().

      Throws:
      UiException - if any component is attached to a page of the desktop.
    • getDevice

      Device getDevice()
      Returns the device that is associated with this desktop.

      Note: the device is shared by all desktops of the same device type.

    • isAlive

      boolean isAlive()
      Returns whether the desktop is still alive. It returns false once it is destroyed.
      See Also:
    • getId

      String getId()
      Returns ID of this desktop. It is unique in the whole session.
    • getExecution

      Execution getExecution()
      Returns the execution, or null if this desktop is not serving any execution (a.k.a., not locked).
    • getSession

      Session getSession()
      Returns the session of this desktop.
    • getWebApp

      WebApp getWebApp()
      Returns the Web application this desktop belongs to.
    • getPage

      Page getPage(String pageId) throws ComponentNotFoundException
      Returns the page of the specified ID or UUID.

      This is one of the only few method you could access before activating an execution.

      Parameters:
      pageId - the page's ID or UUID. ID has the higher priority.
      Throws:
      ComponentNotFoundException - if page not found
    • getPageIfAny

      Page getPageIfAny(String pageId)
      Returns the page of the specified ID or UUID, or null if no such page.
      Parameters:
      pageId - the page's ID or UUID. ID has the higher priority.
      Since:
      2.4.1
    • getPages

      Collection<Page> getPages()
      Returns a readonly collection of all Page in this desktop.
    • getFirstPage

      Page getFirstPage()
      Returns the first page, or null if no page at all (happens when the desktop has been destroyed)
      Since:
      5.0.3
    • hasPage

      boolean hasPage(String pageId)
      Returns whether a page exists.
    • getAttributes

      Map<String,Object> getAttributes()
      Returns all custom attributes associated with this desktop.
      Specified by:
      getAttributes in interface Scope
    • getAttribute

      Object getAttribute(String name)
      Returns the value of the specified custom attribute associated with the desktop.
      Specified by:
      getAttribute in interface Scope
    • setAttribute

      Object setAttribute(String name, Object value)
      Sets the value of the specified custom attribute associated with the desktop.
      Specified by:
      setAttribute in interface Scope
      Returns:
      the previous value associated with the attribute, if any
    • removeAttribute

      Object removeAttribute(String name)
      Removes the specified custom attribute associated with the desktop.
      Specified by:
      removeAttribute in interface Scope
      Returns:
      the previous value associated with the attribute, if any,
    • getComponents

      Collection<Component> getComponents()
      Returns all components contained in this desktop.
    • getComponentByUuid

      Component getComponentByUuid(String uuid)
      Returns the component of the specified UUID (Component.getUuid()).
      Throws:
      ComponentNotFoundException - if component not found
    • getComponentByUuidIfAny

      Component getComponentByUuidIfAny(String uuid)
      Returns the component of the specified UUID (Component.getUuid()), or null if not found.
    • getUpdateURI

      String getUpdateURI(String pathInfo)
      Returns the URI for asynchronous update.

      You rarely need this method unless for implementing special components, such as file upload.

      Parameters:
      pathInfo - the path to append to the returned URI, or null to ignore
    • getRequestPath

      String getRequestPath()
      Returns the path of the request that causes this desktop to be created, or "" if not available. In other words, it is the request path of the first page (see Page.getRequestPath()).

      For example, "/foo/index.zul" (a ZUML page is requested) or /test (a richlet).

      Since:
      3.0.0
      See Also:
    • getQueryString

      String getQueryString()
      Returns the query string that is contained in the request URL after the path (getRequestPath()), or null if the URL does not have a query string.
      Since:
      5.0.2
    • getCurrentDirectory

      String getCurrentDirectory()
      Returns the current directory (never null). It is empty if no current directory at all. Otherwise, it must end with '/'. In other words, you could use getCurrentDirectory() + relative_path.
    • setCurrentDirectory

      void setCurrentDirectory(String dir)
      Sets the current directory.
      Parameters:
      dir - the current directory. If null, an empty string is assumed (means no current directory at all).
    • getBookmark

      String getBookmark()
      Returns the current bookmark (never null). The returned might be the same as the last call to setBookmark(java.lang.String), because user might use BACK, FORWARD or others to change the bookmark.
    • setBookmark

      void setBookmark(String name)
      Sets a bookmark to this desktop. Then, when user press BACK, FORWARD or specify an URL with this bookmark, the onBookmarkChange event is sent to all pages of the desktop.

      It is the same as setBookmark(name, false)

    • setBookmark

      void setBookmark(String name, boolean replace)
      Sets the bookmark to this desktop. with more control.
      Parameters:
      name - the name of the bookmark
      replace - if true, the bookmark is replaced (in the history list)
      Since:
      3.6.4
      See Also:
    • getDynamicMediaURI

      String getDynamicMediaURI(Component comp, String pathInfo)
      Returns URI for a dynamic generated media associated with a component. ZK Update Engine will then invoke invoke DynamicMedia.getMedia(java.lang.String) to response.

      Note: to use with this method, DynamicMedia must be implemented as part of the object returned by ComponentCtrl.getExtraCtrl().

      Used mainly for component implementation.

    • getDownloadMediaURI

      String getDownloadMediaURI(org.zkoss.util.media.Media media, String pathInfo)
      Returns URI for a media that is used to download to the client. The client will open a Save As dialog to save the specified file.

      Note: once called, the media belongs to desktop and it is purged automatically. Thus, don't access it again after calling this method.

    • enableServerPush

      boolean enableServerPush(boolean enable)
      Enables or disables the server-push feature. Before using any server-push threads, you have to enable it for the particular desktop first by use of this method. Refer to Executions.activate(org.zkoss.zk.ui.Desktop) for more details.

      Default: false

      This method uses the default class (defined by Device.getServerPushClass()) to instantiate the server-push controller.

      Parameters:
      enable - whether to enable or to disable the server-push feature.
      Since:
      3.0.0
      See Also:
    • isServerPushEnabled

      boolean isServerPushEnabled()
      Returns whether the server-push feature is enabled for this desktop.

      Default: false.

      Since:
      3.0.0
    • addListener

      void addListener(Object listener)
      Adds a listener.

      Note: if the listener is added twice, it will be invoked twice when a corresponding event occurs.

      Parameters:
      listener - the listener. It cannot be null. It must be an instance that implements DesktopCleanup, ExecutionInit, ExecutionCleanup, UiLifeCycle, EventInterceptor and/or AuService.
      Note: DesktopInit, EventThreadInit, EventThreadCleanup, EventThreadSuspend and EventThreadResume are not supported.
      Throws:
      IllegalArgumentException - if not a valid listener.
      Since:
      3.0.6
    • removeListener

      boolean removeListener(Object listener)
      Removes a listener.
      Returns:
      whether the listener is removed successfully. Object.equals(java.lang.Object) is used to check whether a listener is added.
      Since:
      3.0.6
    • invalidate

      void invalidate()
      Invalidates the desktop. All pages will be redrawn.
      Since:
      3.0.6
    • getStorage

      Storage getStorage()
      Returns the storage in a desktop scope.
      Returns:
      a storage implementation, never null.
      Since:
      8.0.0
    • pushHistoryState

      void pushHistoryState(Object state, String title, String url)
      Pushes a new history state.
      Parameters:
      state - a state object.
      title - a title for the state. May be ignored by some browsers.
      url - the history entry's URL. Could be null.
      Since:
      8.5.0
    • replaceHistoryState

      void replaceHistoryState(Object state, String title, String url)
      Replaces the current history state.
      Parameters:
      state - a state object.
      title - a title for the state. May be ignored by some browsers.
      url - the history entry's URL. Could be null.
      Since:
      8.5.0
    • getResourceURI

      default String getResourceURI(String pathInfo)
      Returns the URI for ZK resource.
      Parameters:
      pathInfo - the path to append to the returned URI, or null to ignore
      Since:
      9.5.0