Interface Component

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean addEventListener​(int priority, java.lang.String evtnm, EventListener<? extends Event> listener)
      Adds an event listener to specified event name for this component with the given priority.
      boolean addEventListener​(java.lang.String evtnm, EventListener<? extends Event> listener)
      Adds an event listener to specified event name for this component.
      boolean addForward​(java.lang.String originalEvent, java.lang.String targetPath, java.lang.String targetEvent)
      Adds a forward condition to forward the event received by this component to another component, specified with a path.
      boolean addForward​(java.lang.String originalEvent, java.lang.String targetPath, java.lang.String targetEvent, java.lang.Object eventData)
      Adds a forward condition to forward the event received by this component to another component of the specified path with extra event data.
      boolean addForward​(java.lang.String originalEvent, Component target, java.lang.String targetEvent)
      Adds a forward condition to forward the event received by this component to another component.
      boolean addForward​(java.lang.String originalEvent, Component target, java.lang.String targetEvent, java.lang.Object eventData)
      Adds a forward condition to forward the event received by this component to another component with extra event data.
      boolean appendChild​(Component child)
      Appends a child.
      void applyProperties()
      Initializes the properties (a.k.a. members) based on what are defined in the component definition.
      java.lang.Object clone()
      Clones the component.
      void detach()
      Detaches this component such that it won't belong to any page.
      java.lang.Object getAttribute​(java.lang.String name)
      Returns the custom attribute associated with this component, i.e., COMPONENT_SCOPE.
      java.lang.Object getAttribute​(java.lang.String name, int scope)
      Returns the value of the specified custom attribute in the specified scope, or null if not defined.
      java.lang.Object getAttributeOrFellow​(java.lang.String name, boolean recurse)
      Returns the custom attribute associated with this component, or the fellow of this component; or null if not found.
      java.util.Map<java.lang.String,​java.lang.Object> getAttributes()
      Returns all custom attributes associated with this component, i.e., COMPONENT_SCOPE.
      java.util.Map<java.lang.String,​java.lang.Object> getAttributes​(int scope)
      Returns all custom attributes of the specified scope.
      AuService getAuService()
      Returns an AU service to process the AU request before the component's default handling.
      java.lang.String getAutag()
      Returns the AU tag for this widget.
      <T extends Component>
      java.util.List<T>
      getChildren()
      Returns a live list of children.
      java.lang.String getClientAttribute​(java.lang.String name)
      Returns the value of a DOM attribute
      java.lang.String getClientDataAttribute​(java.lang.String name)
      Returns the value of a DOM data attribute
      ComponentDefinition getDefinition()
      Returns the component definition of this component (never null).
      Desktop getDesktop()
      Returns the desktop of this component, or null if this component doesn't belong to any desktop.
      java.lang.Iterable<EventListener<? extends Event>> getEventListeners​(java.lang.String evtnm)
      Returns an iterable collection of the event listeners for the given event.
      Component getFellow​(java.lang.String id)
      Returns a component of the specified ID in the same ID space.
      Component getFellow​(java.lang.String id, boolean recurse)
      Returns a component of the specified ID in the same ID space.
      Component getFellowIfAny​(java.lang.String id)
      Returns a component of the specified ID in the same ID space, or null if not found.
      Component getFellowIfAny​(java.lang.String id, boolean recurse)
      Returns a component of the specified ID in the same ID space, or null if not found.
      java.util.Collection<Component> getFellows()
      Returns all fellows in the same ID space of this component.
      Component getFirstChild()
      Returns the first child component, or null if no child at all.
      java.lang.String getId()
      Returns the ID.
      Component getLastChild()
      Returns the last child component, or null if no child at all.
      java.lang.String getMold()
      Returns the mold used to render this component.
      Component getNextSibling()
      Returns the next sibling, or null if it is the last child.
      Page getPage()
      Returns the page that this component belongs to, or null if it doesn't belong to any page.
      Component getParent()
      Returns the parent component, or null if this is the root component.
      Component getPreviousSibling()
      Returns the previous sibling, or null if it is the first child.
      Component getRoot()
      Returns the root of this component.
      java.lang.Object getShadowVariable​(java.lang.String name, boolean recurse)
      Returns the shadow variable associated with this component or its parent component; or null if not found.
      java.lang.Object getShadowVariable​(Component baseChild, java.lang.String name, boolean recurse)
      Returns the shadow variable enclosed with the base component, which associated with this component or its parent component; or null if not found.
      IdSpace getSpaceOwner()
      Returns the owner of the ID space that this component belongs to.
      java.lang.String getStubonly()
      Returns whether this component is stub-only.
      Template getTemplate​(java.lang.String name)
      Returns the template of the given name, or null if not available.
      java.util.Set<java.lang.String> getTemplateNames()
      Returns a readonly set of the names of all templates.
      java.lang.String getUuid()
      Returns UUID (universal unique ID) which is unique in the whole session.
      java.util.Set<java.lang.String> getWidgetAttributeNames()
      Returns a read-only collection of additions DOM attributes that shall be generated.
      java.lang.String getWidgetClass()
      Returns the widget class (a.k.a., the widget type), or null if not available.
      java.lang.String getWidgetListener​(java.lang.String evtnm)
      Returns the script of the client event, or null if not found.
      java.util.Set<java.lang.String> getWidgetListenerNames()
      Returns a read-only collection of event names (String) that the listener of the peer widget are assigned, or an empty collection if none is registered.
      java.lang.String getWidgetOverride​(java.lang.String name)
      Returns the script of the method definition to override widget's method, or null if not found.
      java.util.Set<java.lang.String> getWidgetOverrideNames()
      Returns a read-only collection of the property names (String) that shall be overridden, or an empty collection if none is registered.
      boolean hasAttribute​(java.lang.String name)
      Returns if the custom attribute is associate with this component.
      boolean hasAttribute​(java.lang.String name, int scope)
      Returns if the custom attribute is associate with this component.
      boolean hasAttributeOrFellow​(java.lang.String name, boolean recurse)
      Returns if a custom attribute is associated with this component, or the fellow of this component.
      boolean hasFellow​(java.lang.String compId)
      Returns whether a fellow exists in the same ID space of this component.
      boolean hasFellow​(java.lang.String id, boolean recurse)
      Returns whether there is a fellow named with the specified component ID in the same ID space as this component.
      boolean insertBefore​(Component newChild, Component refChild)
      Inserts a child before the reference child.
      void invalidate()
      Invalidates this component by setting the dirty flag such that it will be redraw the whole content of this component and its dependencies later.
      boolean isInvalidated()
      Returns if this component needs to be redrawn at the client.
      boolean isListenerAvailable​(java.lang.String evtnm, boolean asap)
      Returns whether the event listener is available.
      boolean isVisible()
      Returns whether this component is visible.
      Component query​(java.lang.String selector)
      Find the first component that matches the given CSS3 selector.
      java.lang.Iterable<Component> queryAll​(java.lang.String selector)
      Returns an iterable object for components that match the given CSS3 selector.
      java.lang.Object removeAttribute​(java.lang.String name)
      Removes the custom attribute associated with this component, i.e., COMPONENT_SCOPE.
      java.lang.Object removeAttribute​(java.lang.String name, int scope)
      Removes the specified custom attribute in the specified scope.
      boolean removeChild​(Component child)
      Removes a child.
      boolean removeEventListener​(java.lang.String evtnm, EventListener<? extends Event> listener)
      Removes an event listener.
      boolean removeForward​(java.lang.String originalEvent, java.lang.String targetPath, java.lang.String targetEvent)
      Removes a forward condition that was added by addForward(String, String, String).
      boolean removeForward​(java.lang.String originalEvent, Component target, java.lang.String targetEvent)
      Removes a forward condition that was added by addForward(String, Component, String).
      java.lang.Object setAttribute​(java.lang.String name, java.lang.Object value)
      Sets the custom attribute associated with this component, i.e., COMPONENT_SCOPE.
      java.lang.Object setAttribute​(java.lang.String name, java.lang.Object value, int scope)
      Sets the value of the specified custom attribute in the specified scope.
      void setAuService​(AuService service)
      Sets an AU service to process the AU request before the component's default handling.
      void setAutag​(java.lang.String tag)
      Sets the AU tag for this widget.
      java.lang.String setClientAttribute​(java.lang.String name, java.lang.String value)
      Sets or removes a DOM attribute of the peer widget (at the client).
      java.lang.String setClientDataAttribute​(java.lang.String name, java.lang.String value)
      Sets a DOM data attribute of the peer widget (at the client).
      void setId​(java.lang.String id)
      Sets the ID.
      void setMold​(java.lang.String mold)
      Sets the mold to render this component.
      void setPage​(Page page)
      Sets what page this component belongs to.
      void setPageBefore​(Page page, Component refRoot)
      Sets what page this component belongs to, and insert this component right before the reference component.
      void setParent​(Component parent)
      Sets the parent component.
      void setStubonly​(boolean stubonly)
      Sets whether this component is stub-only.
      void setStubonly​(java.lang.String stubonly)
      Sets whether this component is stub-only.
      Template setTemplate​(java.lang.String name, Template template)
      Sets a UI template which could be retrieved later with getTemplate(java.lang.String).
      boolean setVisible​(boolean visible)
      Sets whether this component is visible.
      void setWidgetClass​(java.lang.String clsnm)
      Sets the widget class (a.k.a., the widget type).
      java.lang.String setWidgetListener​(java.lang.String evtnm, java.lang.String script)
      Sets or removes an event listener of the peer widget.
      java.lang.String setWidgetOverride​(java.lang.String name, java.lang.String script)
      Sets or removes a method or a property of the peer widget (at the client).
    • Method Detail

      • getWidgetClass

        java.lang.String getWidgetClass()
        Returns the widget class (a.k.a., the widget type), or null if not available. The widget class is a JavaScript class, including the package name. For example, "zul.wnd.Window".

        Default: the widget class is decided by the component definition (ComponentDefinition) and the mold (getMold()).

        To override in Java, you could invoke setWidgetClass(java.lang.String). To override in ZUML, you could use the client namespace as follows.

        
                <window xmlns:w="http://www.zkoss.org/2005/zk/client"
                w:use="foo.MyWindow">
                </window>
        

        Note: for Ajax devices, the widget class must be non-null.

        Since:
        5.0.0
        See Also:
        setWidgetClass(java.lang.String)
      • setWidgetClass

        void setWidgetClass​(java.lang.String clsnm)
        Sets the widget class (a.k.a., the widget type). The widget class is a JavaScript class, including the package name. For example, "zul.wnd.Window".
        Parameters:
        clsnm - the widget's class name at the client side. If null (or empty), the default one is used (see getWidgetClass()).
        Since:
        5.0.2
      • getDefinition

        ComponentDefinition getDefinition()
        Returns the component definition of this component (never null).
      • getId

        java.lang.String getId()
        Returns the ID.

        Default: "" (an empty string; it means no ID at all).

        If a component belongs to an ID space (see IdSpace), the ID must also be unique in the ID space it belongs. any its parent and ancestor implements IdSpace. If it is a root component (i.e., without any parent), its ID must be unique among root components of the same page.

        A page itself is also an ID space, so you could retrieve components in a page by use of IdSpace.getFellow(java.lang.String), unless the component is a descendant of another component that implements IdSpace. In this case, you have to retrieve the parent first (by use of IdSpace.getFellow(java.lang.String) and then use getFellow(java.lang.String) against the owner of the ID space.

        In zscript and EL, a component with explicit ID can be accessed directly by the ID.

        See Also:
        Path
      • setId

        void setId​(java.lang.String id)
        Sets the ID. The scope of uniqueness depends on whether this component is a root component. Refer to getId() for more details.

        Default: "" (an empty string; it means no ID at all).

        Parameters:
        id - the identifier. You could specify null or an empty string to remove ID.
        See Also:
        Selectors
      • getDesktop

        Desktop getDesktop()
        Returns the desktop of this component, or null if this component doesn't belong to any desktop.

        When a component is created in an event listener, it is assigned to the current desktop automatically. If a component is created not in any event listener, it doesn't belong to any desktop and this method returns null. Once a component is attached to a desktop (by use of setPage(org.zkoss.zk.ui.Page) or setParent(org.zkoss.zk.ui.Component)), it belongs to the desktop.

        Notice: there is no way to detach a component from a desktop, once it is attached as described above. In other words, you cannot move a component (or page) from one desktop to another.

        In summary, there are only two ways to handle components.

        1. Handle them all in event listeners and don't access any components from other desktops. This is simplest and clearest.
        2. Creates components in another thread (other than event listener) and attach them to a page (and then desktop) upon an event is received.
      • getPage

        Page getPage()
        Returns the page that this component belongs to, or null if it doesn't belong to any page.

        When a component is created (a.k.a., constructed), it doesn't belong to any page. And, if a component doesn't belong to any page, they won't be displayed at the client.

        When changing parent (setParent(org.zkoss.zk.ui.Component)), the child component's page will become the same as parent's. In other words, a component is added to a page automatically if it becomes a child of another component (who belongs to a page).

        For root components, you have to invoke setPage(org.zkoss.zk.ui.Page) Explicitly.

        See Also:
        setParent(org.zkoss.zk.ui.Component), setPage(org.zkoss.zk.ui.Page)
      • setPageBefore

        void setPageBefore​(Page page,
                           Component refRoot)
        Sets what page this component belongs to, and insert this component right before the reference component.

        For child components, the page they belong is maintained automatically. You need to invoke this method only for root components.

        It is similar to setPage(org.zkoss.zk.ui.Page), except this component will be placed before the reference component. If the reference component is null, this component is placed at the end of all root components.

        Parameters:
        refRoot - another root component used as a reference which this component will be placed before. If null, this component will be placed at the end of all root components (no matter whether it already belongs to the same page).
        Since:
        3.0.0
        See Also:
        setPage(org.zkoss.zk.ui.Page)
      • getUuid

        java.lang.String getUuid()
        Returns UUID (universal unique ID) which is unique in the whole session. The UUID is generated automatically and immutable, unless RawId is also implemented.

        It is mainly used for communication between client and server and you rarely need to access it.

        If RawId is implemented as part of a component, UUID is the same as getId() if setId(java.lang.String) is ever called. It is designed to migrate HTML pages to ZK, such that the element ID could remain the same.

      • getFellowIfAny

        Component getFellowIfAny​(java.lang.String id)
        Returns a component of the specified ID in the same ID space, or null if not found.

        Unlike getFellow(java.lang.String), it returns null if not found.

      • getFellowIfAny

        Component getFellowIfAny​(java.lang.String id,
                                 boolean recurse)
        Returns a component of the specified ID in the same ID space, or null if not found. It is the same as getSpaceOwner().getFellowIfAny(id, recurse);

        Unlike getFellow(String, boolean), it returns null if not found.

        Parameters:
        recurse - whether to look up the parent ID space for the existence of the fellow
        Since:
        5.0.0
      • getFellows

        java.util.Collection<Component> getFellows()
        Returns all fellows in the same ID space of this component. Notice that only components that are assigned with ID are considered as fellows. The returned collection is read-only.
        Since:
        3.0.6
      • hasFellow

        boolean hasFellow​(java.lang.String id,
                          boolean recurse)
        Returns whether there is a fellow named with the specified component ID in the same ID space as this component. It is the same as getSpaceOwner().hasFellow(id, recurse);
        Parameters:
        recurse - whether to look up the parent ID space for the existence of the fellow
        Since:
        5.0.0
      • hasFellow

        boolean hasFellow​(java.lang.String compId)
        Returns whether a fellow exists in the same ID space of this component.
        Since:
        5.0.0
      • getNextSibling

        Component getNextSibling()
        Returns the next sibling, or null if it is the last child.
        Since:
        3.0.0
      • getPreviousSibling

        Component getPreviousSibling()
        Returns the previous sibling, or null if it is the first child.
        Since:
        3.0.0
      • getFirstChild

        Component getFirstChild()
        Returns the first child component, or null if no child at all.
        Since:
        3.0.0
      • getLastChild

        Component getLastChild()
        Returns the last child component, or null if no child at all.
        Since:
        3.0.0
      • getAttributes

        java.util.Map<java.lang.String,​java.lang.Object> getAttributes​(int scope)
        Returns all custom attributes of the specified scope. You could reference them by use of componentScope, spaceScope, pageScope, requestScope and desktopScope in zscript and EL.

        If scope is COMPONENT_SCOPE, it means custom attributes private to this component.

        If scope is SPACE_SCOPE, it means custom attributes shared by components from the same ID space as this one's.

        If scope is PAGE_SCOPE, it means custom attributes shared by components from the same page as this one's.

        If scope is DESKTOP_SCOPE, it means custom attributes shared by components from the same desktops this one's.

        Parameters:
        scope - one of COMPONENT_SCOPE, SPACE_SCOPE, PAGE_SCOPE, DESKTOP_SCOPE, SESSION_SCOPE, REQUEST_SCOPE or APPLICATION_SCOPE,
      • getAttributes

        java.util.Map<java.lang.String,​java.lang.Object> getAttributes()
        Returns all custom attributes associated with this component, i.e., COMPONENT_SCOPE.
        Specified by:
        getAttributes in interface Scope
      • getAttribute

        java.lang.Object getAttribute​(java.lang.String name,
                                      int scope)
        Returns the value of the specified custom attribute in the specified scope, or null if not defined.

        If scope is COMPONENT_SCOPE, it means attributes private to this component.

        If scope is SPACE_SCOPE, it means custom attributes shared by components from the same ID space as this one's.

        If scope is PAGE_SCOPE, it means custom attributes shared by components from the same page as this one's.

        If scope is DESKTOP_SCOPE, it means custom attributes shared by components from the same desktop as this one's.

        Parameters:
        scope - one of COMPONENT_SCOPE, SPACE_SCOPE, PAGE_SCOPE, DESKTOP_SCOPE, SESSION_SCOPE, REQUEST_SCOPE or APPLICATION_SCOPE,
      • getAttribute

        java.lang.Object getAttribute​(java.lang.String name)
        Returns the custom attribute associated with this component, i.e., COMPONENT_SCOPE.
        Specified by:
        getAttribute in interface Scope
      • hasAttribute

        boolean hasAttribute​(java.lang.String name)
        Returns if the custom attribute is associate with this component.

        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, int).

        Specified by:
        hasAttribute in interface Scope
        Since:
        5.0.0
      • setAttribute

        java.lang.Object setAttribute​(java.lang.String name,
                                      java.lang.Object value)
        Sets the custom attribute associated with this component, i.e., COMPONENT_SCOPE.
        Specified by:
        setAttribute in interface Scope
        Returns:
        the previous value associated with the attribute, if any
      • removeAttribute

        java.lang.Object removeAttribute​(java.lang.String name)
        Removes the custom attribute associated with this component, i.e., COMPONENT_SCOPE.
        Specified by:
        removeAttribute in interface Scope
        Returns:
        the previous value associated with the attribute, if any,
      • getAttributeOrFellow

        java.lang.Object getAttributeOrFellow​(java.lang.String name,
                                              boolean recurse)
        Returns the custom attribute associated with this component, or the fellow of this component; or null if not found.

        Notice that it doesn't check any variable defined in VariableResolver (of Page.addVariableResolver(org.zkoss.xel.VariableResolver)).

        Parameters:
        recurse - whether to look up the parent component for the existence of the attribute.
        Notice that, if recurse is false and this component is not an ID space owner, it won't look at the fellow.
        If recurse is true, it will look up all parents, page, desktop, session and application until found. If any of them is a space owner, the fellows will be searched.
        Since:
        5.0.0
      • getShadowVariable

        java.lang.Object getShadowVariable​(java.lang.String name,
                                           boolean recurse)
        Returns the shadow variable associated with this component or its parent component; or null if not found.

        Notice that it doesn't check any variable defined in VariableResolver (of Page.addVariableResolver(org.zkoss.xel.VariableResolver)).

        Parameters:
        recurse - whether to look up the parent component for the existence of the shadow variable.
        If recurse is true, it will look up all parents until found. If any of them is a shadow host.
        Since:
        8.0.0
      • getShadowVariable

        java.lang.Object getShadowVariable​(Component baseChild,
                                           java.lang.String name,
                                           boolean recurse)
        Returns the shadow variable enclosed with the base component, which associated with this component or its parent component; or null if not found.

        Notice that it doesn't check any variable defined in VariableResolver (of Page.addVariableResolver(org.zkoss.xel.VariableResolver)).

        Parameters:
        baseChild - the base component to seek the variable.
        recurse - whether to look up the parent component for the existence of the shadow variable.
        If recurse is true, it will look up all parents until found. If any of them is a shadow host.
        Since:
        8.0.1
        See Also:
        getShadowVariable(String, boolean)
      • hasAttributeOrFellow

        boolean hasAttributeOrFellow​(java.lang.String name,
                                     boolean recurse)
        Returns if a custom attribute is associated with this component, or the fellow of this component.

        Notice that it doesn't check any variable defined in VariableResolver (of Page.addVariableResolver(org.zkoss.xel.VariableResolver)).

        Parameters:
        recurse - whether to look up the parent component for the existence of the attribute.
        Notice that, if recurse is false and this component is not an ID space owner, it won't look at the fellow.
        If recurse is true, it will look up all parents, page, desktop, session and application until found. If any of them is a space owner, the fellows will be searched.
        Since:
        5.0.0
      • getStubonly

        java.lang.String getStubonly()
        Returns whether this component is stub-only. By stub-only, we mean we don't need to maintain the states of the component at the server side.

        There are three possible values: "true", "false", and "inherit", and "ignore-native".

        Notice that the native components will be stub-ized, no matter this property is set. Though rarely required, you could control whether to stub-ize the native components with a component attribute called Attributes.STUB_NATIVE.

        Since:
        5.0.4
      • setStubonly

        void setStubonly​(java.lang.String stubonly)
        Sets whether this component is stub-only. By stub-only, we mean we don't need to maintain the states of the component at the server side.

        Default: "inherit" (i.e., the same as the parent's stub-only, and "false" is assumed if none of parents is specified with stub-only).

        If a component is set to stub-only, the application running at the server shall not access it anymore after rendered to the client. The ZK loader will try to minimize the memory footprint by merging stub-only components and replacing with light-weight components.

        However, the event listeners and handlers are preserved, so they will be invoked if the corresponding event is received. Since the original component is gone, the event is the more generic format: an instance of Event (rather than MouseEvent or others).

        If a component is stub-only, the application usually access it only at the client since all widgets are preserved at the client (so are events).

        This method is available only for ZK EE.

        Parameters:
        stubonly - whether it is stub-only. The allowed values include "true", "false" and "inherit".
        Since:
        5.0.4
      • setStubonly

        void setStubonly​(boolean stubonly)
        Sets whether this component is stub-only. It is the same as setStubonly(stubonly ? "true": "false").
        Since:
        6.0.0
      • getParent

        Component getParent()
        Returns the parent component, or null if this is the root component.
      • getChildren

        <T extends Component> java.util.List<T> getChildren()
        Returns a live list of children. By live we mean the developer could add or remove a child by manipulating the returned list directly.
      • getRoot

        Component getRoot()
        Returns the root of this component.
      • setVisible

        boolean setVisible​(boolean visible)
        Sets whether this component is visible. A component is visible by default. Both visible and invisible components are rendered in a browser's DOM. But an invisible component's DOM elements with CSS display:none. Since a DOM element will inherit its parent's CSS rules, a component is visible only if all of its parents are also visible.
        To remove a component's DOM elements, use detach().
        Returns:
        the previous visibility
      • getMold

        java.lang.String getMold()
        Returns the mold used to render this component.

        Default: "default"

        Since 5.0, the default can be overridden by specify a library property. For example, if the component's class name is org.zkoss.zul.Button, then you can override the default mold by specifying the property called "org.zkoss.zul.Button.mold" with the mold you want in zk.xml. For example,

        <library-property>
                <name>org.zkoss.zul.Button.mold</name>
                <value>trendy</value>
                </library-property>

        Notice that it doesn't affect the deriving classes. If you want to change the deriving class's default mold, you have to specify them explicitly, too.

        See Also:
        ComponentDefinition
      • setMold

        void setMold​(java.lang.String mold)
        Sets the mold to render this component.
        Parameters:
        mold - the mold. If null or empty, "default" is assumed.
        See Also:
        ComponentDefinition
      • addEventListener

        boolean addEventListener​(int priority,
                                 java.lang.String evtnm,
                                 EventListener<? extends Event> listener)
        Adds an event listener to specified event name for this component with the given priority.

        You could register listener to all components in the same page by use of Page.addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener<? extends org.zkoss.zk.ui.event.Event>).

        Version Difference

        ZK 5.0 and earlier, the second registration is ignored if an event listener has been registered twice. However, since 6.0.0 and later, it won't be ignored. If a listener has been registered multiple times, it will be invoked multiple times.

        If you prefer to ignore the second registration, you could specify a library property called "org.zkoss.zk.ui.EventListener.duplicateIgnored" to true.

        Parameters:
        priority - the priority of the event. The higher the priority is, the earlier it is invoked.
        Notice:
        • If the priority equals or is greater than 1000, the event listener will be invoked before the event handlers registered in a ZUML page (i.e., the onXxx attribute declared in ZUML). On the other hand, if the priority is lower than 1000, it is invoked after the ZUML's event handler.
        • The priority registered by addEventListener(String, EventListener) is 0.
        • Applications shall not use the priority higher than 10,000 and lower than -10,000 since they are reserved for component development.
        evtnm - what event to listen (never null)
        Returns:
        whether the listener is added successfully
        Since:
        6.0.0
        See Also:
        Page.addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener<? extends org.zkoss.zk.ui.event.Event>)
      • removeEventListener

        boolean removeEventListener​(java.lang.String evtnm,
                                    EventListener<? extends Event> listener)
        Removes an event listener.
        Returns:
        whether the listener is removed; false if it was never added.
      • addForward

        boolean addForward​(java.lang.String originalEvent,
                           Component target,
                           java.lang.String targetEvent)
        Adds a forward condition to forward the event received by this component to another component.

        Default: no forward condition at all.

        Once the condition is added, a event called targetEvent is posted to the target component, when this component receives the orginalEvent event.

        Parameters:
        originalEvent - the original event that was received by this component. If null, "onClick" is assumed.
        target - the target component to receive the event. If null, the space owner getSpaceOwner() is assumed. If null and the space owner is the page, the root component is assumed.
        targetEvent - the target event that the target component will receive. If null, it is the same as the original event.
        Returns:
        whether it is added successfully. It returns false if the condition was always added before.
        Since:
        3.0.0
        See Also:
        removeForward(String, Component, String), addForward(String, Component, String, Object)
      • addForward

        boolean addForward​(java.lang.String originalEvent,
                           java.lang.String targetPath,
                           java.lang.String targetEvent)
        Adds a forward condition to forward the event received by this component to another component, specified with a path.

        Note: the target component is retrieved from the path, each time the event is received. Thus, you can reference to a component that is created later.

        Parameters:
        originalEvent - the original event that was received by this component. If null, "onClick" is assumed.
        targetPath - the target component's path related to this component. If ".", this component is assumed. If null, the space owner is assumed. If null and the space owner is the page, the root component is assumed.
        targetEvent - the target event that the target component will receive. If null, it is the same as the original event.
        Returns:
        whether it is added successfully. It returns false if the condition was always added before.
        Since:
        3.0.0
        See Also:
        addForward(String, Component, String), removeForward(String, String, String)
      • addForward

        boolean addForward​(java.lang.String originalEvent,
                           Component target,
                           java.lang.String targetEvent,
                           java.lang.Object eventData)
        Adds a forward condition to forward the event received by this component to another component with extra event data.
        Parameters:
        eventData - the extra data that can be retrieve by Event.getData().
        Since:
        3.0.6
        See Also:
        addForward(String, Component, String)
      • addForward

        boolean addForward​(java.lang.String originalEvent,
                           java.lang.String targetPath,
                           java.lang.String targetEvent,
                           java.lang.Object eventData)
        Adds a forward condition to forward the event received by this component to another component of the specified path with extra event data.
        Parameters:
        eventData - the extra data that can be retrieve by Event.getData().
        Since:
        3.0.6
        See Also:
        addForward(String, String, String)
      • removeForward

        boolean removeForward​(java.lang.String originalEvent,
                              java.lang.String targetPath,
                              java.lang.String targetEvent)
        Removes a forward condition that was added by addForward(String, String, String). If no such forward condition exists, nothing happens but return false.
        Parameters:
        originalEvent - the original event that was received by this component. It must be the same as the one passed to addForward(String, Component, String).
        targetPath - the target component's path related to this component. If ".", this component is assumed. If null, the space owner is assumed. If null and the space owner is the page, the root component is assumed.
        targetEvent - the target event that the target component will receive. It must be the same as the one passed to addForward(String, Component, String).
        Returns:
        whether the forward is removed successfully. It returns false if the forward condition is not found
        Since:
        3.0.0
        See Also:
        addForward(String, String, String)
      • isInvalidated

        boolean isInvalidated()
        Returns if this component needs to be redrawn at the client.

        Application developers rarely need to call this method.

        Note:

        1. It always returns true if it doesn't belong to any page (since redraw is required if it is attached to a page later).
        2. It always returns true if the current execution is not an asynchronous update (so redrawn is always required).
        3. If its parent is invalidated, this component will be redrawn too, but this method returns false if invalidate() was not called against this component.
        Since:
        3.0.5
      • invalidate

        void invalidate()
        Invalidates this component by setting the dirty flag such that it will be redraw the whole content of this component and its dependencies later. And, the widget associated with this component and all its descendant at the client will be deleted and recreated, too.

        If the application is totally controlled by the server side (i.e., you don't write client codes), you rarely need to access this method.

        It can be called only in the request-processing and event-processing phases. However, it is NOT allowed in the rendering phase.

      • applyProperties

        void applyProperties()
        Initializes the properties (a.k.a. members) based on what are defined in the component definition.

        This method is invoked automatically if a component is created by evaluating a ZUML page, i.e., if it is specified as an element of a ZUML page.

        On the other hand, if it is created manually (by program), developer might choose to invoke this method or not, depending whether he wants to initializes the component with the properties defined in the ZUML page (PageDefinition) and the language definition (LanguageDefinition).

        Notice that, since 5.0.7, custom-attributes are applied automatically in the constructor of AbstractComponent, so they are always available no matter this method is called or not.

      • setWidgetListener

        java.lang.String setWidgetListener​(java.lang.String evtnm,
                                           java.lang.String script)
        Sets or removes an event listener of the peer widget. If there is an event listener associated with the same event, the previous one will be replaced and returned.
        Parameters:
        evtnm - the event name, such as onClick
        script - the script to handle the event. If null, the event handler is removed.
        Returns:
        the previous script if any
        Since:
        5.0.0
      • getWidgetListener

        java.lang.String getWidgetListener​(java.lang.String evtnm)
        Returns the script of the client event, or null if not found.
        Since:
        5.0.0
      • getWidgetListenerNames

        java.util.Set<java.lang.String> getWidgetListenerNames()
        Returns a read-only collection of event names (String) that the listener of the peer widget are assigned, or an empty collection if none is registered.
        Since:
        5.0.0
      • setWidgetOverride

        java.lang.String setWidgetOverride​(java.lang.String name,
                                           java.lang.String script)
        Sets or removes a method or a property of the peer widget (at the client). If there is a method or a property associated with the same name, the previous one will be replaced and returned.

        For example,

        comp.setWidgetOverride("setValue", "function (value) {}"); //override a method
        comp.setWidgetOverride("myfield", "new Date()"); //override a property
        

        If there is no previous method or property, the method/property will be assigned directly.

        Notice that, unlike setWidgetListener(java.lang.String, java.lang.String), if the method has been sent to the client for update, it cannot be removed by calling this method with a null value. In other words, invoking this method with a null value only removes the method overrides if it has not YET been to sent to the client.

        The previous method/property can be accessed by this.$xxx. For example

        function (value, fromServer) {
          this.$setValue(value, fromServer);
          if (this.desktop) {
            this._cnt = !this._cnt;
            this.setStyle('background:'+(this._cnt ? 'red':'green'));
          }
        }

        Notice that, since it is not extending, so this.$super references the superclass's method, rather than the old method.

        Parameters:
        name - the property name to override, such as setValue and miles.
        script - the method definition, such as function (arg) {...}, or a value, such as 123 and new Date(). If not null, this method will be added to the peer widget. If there was a method with the same name, it will be renamed to $name so can you call it back.
        <label w:setValue="function (value) {
          this.$setValue(value); //old method
        }"/>
        If null, the previous method, if any, will be restored.
        Returns:
        the previous script if any
        Since:
        5.0.0
      • getWidgetOverride

        java.lang.String getWidgetOverride​(java.lang.String name)
        Returns the script of the method definition to override widget's method, or null if not found.
        Since:
        5.0.0
      • getWidgetOverrideNames

        java.util.Set<java.lang.String> getWidgetOverrideNames()
        Returns a read-only collection of the property names (String) that shall be overridden, or an empty collection if none is registered.
        Since:
        5.0.0
      • getClientAttribute

        java.lang.String getClientAttribute​(java.lang.String name)
        Returns the value of a DOM attribute
        Since:
        8.0.0
      • setClientDataAttribute

        java.lang.String setClientDataAttribute​(java.lang.String name,
                                                java.lang.String value)
        Sets a DOM data attribute of the peer widget (at the client). If it has previous value, the component will invalidate. ZK pass the attributes directly to the DOM attribute generated at the client.

        Notice that the parameter - name would be expanded by adding the prefix "data-" automatically.

        Parameters:
        name - the attribute name to generate to the DOM element, such as mask.
        value - the value of the attribute. It could be anything depending on the attribute. If null, the attribute will be removed. Make sure to specify an empty string if you want an attribute with an empty value.
        Returns:
        the previous value if any
        Since:
        8.0.0
        See Also:
        setClientDataAttribute(String, String)
      • getClientDataAttribute

        java.lang.String getClientDataAttribute​(java.lang.String name)
        Returns the value of a DOM data attribute

        Notice that the parameter - name would be expanded by adding the prefix "data-" automatically.

        Since:
        8.0.0
        See Also:
        getClientDataAttribute(String)
      • getWidgetAttributeNames

        java.util.Set<java.lang.String> getWidgetAttributeNames()
        Returns a read-only collection of additions DOM attributes that shall be generated. That is, they are the attributes added by setClientAttribute(java.lang.String, java.lang.String).
        Since:
        5.0.3
      • setTemplate

        Template setTemplate​(java.lang.String name,
                             Template template)
        Sets a UI template which could be retrieved later with getTemplate(java.lang.String).
        Parameters:
        name - the template's name. It cannot be empty or null.
        template - the template to assign. If it is null, the previous template, if any, will be removed
        Returns:
        the previous template, if any
      • getTemplateNames

        java.util.Set<java.lang.String> getTemplateNames()
        Returns a readonly set of the names of all templates.
        Since:
        6.0.0
      • setAuService

        void setAuService​(AuService service)
        Sets an AU service to process the AU request before the component's default handling. This method is used if you want to send some custom request from client (by your application).

        Default: null.

        If you want to provide an AU service for the AU requests targeting the desktop. Use Desktop.addListener(java.lang.Object).

        See also How to process AU requests with JSON.

        Since:
        5.0.0
      • getAuService

        AuService getAuService()
        Returns an AU service to process the AU request before the component's default handling.

        Default: null

        Since:
        5.0.0
      • getAutag

        java.lang.String getAutag()
        Returns the AU tag for this widget. The AU tag tag is used to tag the AU requests sent by the peer widget. For instance, if the AU tag is xxx,yyy and the desktop's request path (Desktop.getRequestPath()) is /foo.zul, then the URL of the AU request will contain /_/foo.zul/xxx,yyy,.

        Default: null (no AU tag for this widget).

        Since:
        6.0.0
        See Also:
        setAutag(java.lang.String)
      • setAutag

        void setAutag​(java.lang.String tag)
        Sets the AU tag for this widget. The AU tag tag is used to tag the AU requests sent by the peer widget.
        Parameters:
        tag - the AU tag. Both an empty string and null are considered as null, i.e., no AU tag for this widget.
        Since:
        6.0.0
        See Also:
        getAutag()
      • clone

        java.lang.Object clone()
        Clones the component. All of its children and descendants are cloned. Also, ID are preserved.
        Returns:
        the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.
      • query

        Component query​(java.lang.String selector)
        Find the first component that matches the given CSS3 selector.
        Parameters:
        selector - the CSS3 selector. For example, comp.query("#id div").
        Returns:
        the first matched component, or null if not found
        Since:
        6.0.0
        See Also:
        queryAll(java.lang.String)
      • queryAll

        java.lang.Iterable<Component> queryAll​(java.lang.String selector)
        Returns an iterable object for components that match the given CSS3 selector.

        Notice: this method traverses the whole component tree, only if you iterate through the whole iterable object. In other words, the performance is good, and you can iterate it find the object that matches your criteria.

        Parameters:
        selector - the CSS3 selector. For example, comp.queryAll("#id div").
        Returns:
        a list of all matched component, or an empty list if none is found.
        Since:
        6.0.0
        See Also:
        query(java.lang.String)