Interface Scope

All Known Subinterfaces:
Component, Desktop, Execution, IdSpace, Macro, Page, Session, WebApp
All Known Implementing Classes:
AbstractComponent, AbstractExecution, AbstractPage, AbstractWebApp, DesktopImpl, ExecutionImpl, HtmlBasedComponent, HtmlMacroComponent, HtmlNativeComponent, HtmlShadowElement, PageImpl, SerializableSession, SimpleScope, SimpleSession, SimpleWebApp, StubComponent, StubsComponent, SynchronizedScope, VolatilePage

public interface Scope
Represents a scope of attributes.

In ZK, directly acquiring a lock on a scope for synchronization is uncommon. This method Scopes.getLockForScopeIfAny(Scope) provides a reliable way to obtain a consistent lock object associated with a specific scope, ensuring that synchronization is consistently managed across different parts of the application.

Since:
3.6.0
Author:
tomyeh
See Also:
  • Method Details

    • getAttributes

      Map<String,Object> getAttributes()
      Returns all custom attributes associated with this object (scope).
    • getAttribute

      Object getAttribute(String name)
      Returns the custom attribute associated with this object (scope).
    • getAttribute

      Object getAttribute(String name, boolean recurse)
      Returns the custom attribute associated with this object.
      Parameters:
      recurse - whether to search its ancestor scope. If true and the current scope doen't define the attribute, it searches up its ancestor to see any of them has defined the specified attribute.
      Since:
      5.0.0
    • hasAttribute

      boolean hasAttribute(String name)
      Returns if a custom attribute is associated with this object (scope).

      Notice that null is a valid value, so you can tell if an attribute is associated by examining the return value of getAttribute(java.lang.String).

      Since:
      5.0.0
    • hasAttribute

      boolean hasAttribute(String name, boolean recurse)
      Returns if a custom attribute is associated with this object.

      Notice that null is a valid value, so you can tell if an attribute is associated by examining the return value of getAttribute(java.lang.String).

      Parameters:
      recurse - whether to search its ancestor scope. If true and the current scope doen't define the attribute, it searches up its ancestor to see any of them has defined the specified attribute.
      Since:
      5.0.0
    • setAttribute

      Object setAttribute(String name, Object value)
      Sets (a.k.a., associates) the value for a custom attribute with this object (scope).
      Returns:
      the previous value associated with the attribute, if any
      Since:
      5.0.0
    • setAttribute

      Object setAttribute(String name, Object value, boolean recurse)
      Sets the custom attribute associated with this scope, or the parent scope.
      Parameters:
      recurse - whether to look up the parent scope for the existence of the attribute.
      If recurse is true and the attribute is defined in one of its ancestor (including page), the attribute is replaced. Otherwise, it is the same as setAttribute(String,Object).
      Since:
      5.0.0
    • removeAttribute

      Object removeAttribute(String name)
      Removes the attribute from the current scope if any.
      Returns:
      the previous value associated with the attribute, if any,
      Since:
      5.0.0
    • removeAttribute

      Object removeAttribute(String name, boolean recurse)
      Removes the custom attribute associated with this scope.
      Parameters:
      recurse - whether to look up the parent scope for the existence of the attribute.
      If recurse is true and the attribute is defined in one of its ancestor (including page), the attribute is removed. Otherwise, it is the same as removeAttribute(String).
      Since:
      5.0.0
    • addScopeListener

      boolean addScopeListener(ScopeListener listener)
      Adds a listener to listen whether this scope is changed. The listener is called when a custom attribute is added, removed, or the parent is changed.
      Returns:
      weather the listener is added successfully. Note: if the resolver was added before, it won't be added again and this method returns false.
      Since:
      5.0.0
    • removeScopeListener

      boolean removeScopeListener(ScopeListener listener)
      Removes a change listener from this scope.
      Returns:
      false if listener is not added before.
      Since:
      5.0.0