📄 component.java
字号:
/* Component.java{{IS_NOTE Purpose: Description: History: Mon May 30 21:03:47 2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT This program is distributed under GPL Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zk.ui;import java.util.List;import java.util.Map;import java.util.Iterator;import java.io.Writer;import java.io.IOException;import org.zkoss.zk.ui.metainfo.ComponentDefinition;import org.zkoss.zk.ui.event.EventListener;import org.zkoss.zk.scripting.Namespace;import org.zkoss.zk.au.AuResponse;/** * A UI component. * * <p>There are two kind of lifecycles: one is page creations and the other * is asynchronous updates. * * <h3>The Page Creation</h3> * <p>The page creation occurs when a page is about to render at the first * time. The detailed phases can be found in the devloper's guide. * * <h3>The Asynchronous Update</h3> * <p>The asynchronous update occurs when users does something on the browser, * such as changing the content of input, clicking buttons and so on. * Such behaviors are packed as requests, queue in the browser, and then * send to the server at the proper time. The detailed phases * can be found in the developer's guide. * * <h3>No Synchronization Required</h3> * <p>To simplify the development of components and applications, * invocations of methods of components and event listener are all serialized. * In other words, application and component developers need not worry * synchronization and other thread issues (unless you are developing * background thread to handle long operations). * * <p>It also implies a limitation that you cannot access components * belonging to other desktops when processing an event. * * @author tomyeh */public interface Component extends java.io.Serializable, Cloneable { /** Returns the component definition of this component (never null). */ public ComponentDefinition getDefinition(); /** Returns the owner of the ID space that this component belongs to. * The returned value could be a component, a page or null. * If this component itself implements {@link IdSpace}, this method * returns itself. * If it has an ancestor that implements {@link IdSpace}, * the ancestor is returned. * Otherwise, the page it belongs to is returned * * <p>Each ID space defines an independent set of IDs. No component * in the same ID space could have the same ID. * To get any component in the same ID space, you could use * {@link #getFellow}. * See {@link IdSpace} for more details. * * <p>The ID space relevant methods include {@link #getFellow}, * {@link #getAttribute} and {@link #getVariable}. * * @see #getNamespace */ public IdSpace getSpaceOwner(); /** Returns the ID. If it is a root component (i.e., without parent), * its ID must be unquie among root components of the same page. * * <p>If a component belongs to an ID space (see {@link IdSpace}), * the ID must also be unique in the ID space it belongs. * any its parent and ancestor implements {@link IdSpace}. * * <p>A page itself is also an ID space, so you could retrieve * compnents in a page by use of {@link Page#getFellow}, unless * the component is a descendant of another component that implements * {@link IdSpace}. In this case, you have to retrieve the parent * first (by use of {@link Page#getFellow} and then use {@link #getFellow} * against the owner of the ID space. * * <p>In zscript and EL, a component with explicit ID can be accessed * directly by the ID. In other word, a variable named by the ID is * created automatically. * * @see Page */ public String getId(); /** Sets the ID. The scope of uniqunes depends on whether this component * is a root component. Refer to {@link #getId} for more details. * * <p>When a component is constructed, an ID is generated automatically. * Thus, calling this method only you need to identify a component. * * @see Page */ public void setId(String id); /** Returns the desktop of this component, * or null if this component doesn't belong to any desktop. * * <p>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 (thru {@link #setPage} * or {@link #setParent}), it belongs to the desktop. * * <p>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. * * <p>In summary, there are only two ways to handle components. * <ol> * <li>Handle them all in event listeners and don't access any components * from other desktops. This is simplest and clearest.</li> * <li>Creates components in another thread (other than event listener) * and attach them to a page (and then desktop) upon an event is received.</li> * </ol> */ public Desktop getDesktop(); /** Returns the page that this component belongs to, or null if * it doesn't belong to any page. * * <p>When a component is created (aka., 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. * * <p>When changing parent ({@link #setParent}), 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). * * <p>For root components, you have to invoke {@link #setPage} * explicityly. * * @see #setParent * @see #setPage */ public Page getPage(); /** Sets what page this component belongs to. * If this component already belongs to the same page, nothing * is changed. * * <p>For child components, the page they belong is maintained * automatically. You need to invoke this method only for root * components. */ public void setPage(Page page); /** Sets what page this component belongs to, and insert * this component right before the reference component. * * <p>For child components, the page they belong is maintained * automatically. You need to invoke this method only for root * components. * * <p>It is similar to {@link #setPage}, 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. * * @param 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 */ public void setPageBefore(Page page, Component refRoot); /** Returns UUID (universal unique ID) which is unquie in the whole * session. The UUID is generated automatically and immutable, unless * {@link org.zkoss.zk.ui.ext.RawId} is also implemented. * * <p>It is mainly used for communication between client and server * and you rarely need to access it. * * <p>If {@link org.zkoss.zk.ui.ext.RawId} is implemented as part of * a component, UUID is the same as {@link #getId} if {@link #setId} * is ever called. It is designed to migrate HTML pages to ZK, such * that the element ID could remain the same. */ public String getUuid(); /** Returns a component of the specified ID in the same ID space. * Components in the same ID space are called fellows. * * <p>Unlike {@link #getFellowIfAny}, it throws an exception if not found. * * @exception ComponentNotFoundException is thrown if fellow not found */ public Component getFellow(String id); /** Returns a component of the specified ID in the same ID space, or null * if not found. * <p>Unlike {@link #getFellow}, it returns null if not found. */ public Component getFellowIfAny(String id); /** Returns the next sibling, or null if it is the last child. * @since 3.0.0 */ public Component getNextSibling(); /** Returns the previous sibling, or null if it is the first child. * @since 3.0.0 */ public Component getPreviousSibling(); /** Returns the first child component, or null if no child at all. * @since 3.0.0 */ public Component getFirstChild(); /** Returns the last child component, or null if no child at all. * @since 3.0.0 */ public Component getLastChild(); /** Used with {@link #getAttribute} and relevants to denote * custom attributes private to a component is searched. * <p>It is also known as the component attributes. * <p>It is the same as {@link Component#getAttributes}. */ public static final int COMPONENT_SCOPE = 0; /** Used with {@link #getAttribute} and relevants to denote * custom attributes shared by the same ID space. * <p>It is also known as the ID space attributes. */ public static final int SPACE_SCOPE = 1; /** Used with {@link #getAttribute} and relevants to denote * custom attributes shared by the same page. * <p>It is also known as the page attributes. * <p>It is the same as {@link Page#getAttributes}. */ public static final int PAGE_SCOPE = 2; /** Used with {@link #getAttribute} and relevants to denote * custom attributes shared by the same desktop. * <p>It is also known as the desktop attributes. * <p>It is the same as {@link Desktop#getAttributes}. */ public static final int DESKTOP_SCOPE = 3; /** Used with {@link #getAttribute} and relevants to denote * custom attributes shared by the same session. * <p>It is also known as the session attributes. * <p>It is the same as {@link Session#getAttributes}. */ public static final int SESSION_SCOPE = 4; /** Used with {@link #getAttribute} and relevants to denote * custom attributes shared by the whole application. * <p>It is also known as the application attributes. * <p>It is the same as {@link WebApp#getAttributes}. */ public static final int APPLICATION_SCOPE = 5; /** Used with {@link #getAttribute} and relevants to denote * custom attributes shared by the same request. * <p>It is also known as the request attributes. * <p>It is the same as {@link Execution#getAttributes}. */ public static final int REQUEST_SCOPE = 6; /** Returns all custom attributes of the specified scope. * You could reference them thru componentScope, spaceScope, pageScope, * requestScope and desktopScope in zscript and EL. * * <p>If scope is {@link #COMPONENT_SCOPE}, it means custom attributes private * to this component. * <p>If scope is {@link #SPACE_SCOPE}, it means custom attributes shared * by components from the same ID space as this one's. * <p>If scope is {@link #PAGE_SCOPE}, it means custom attributes shared * by components from the same page as this one's. * <p>If scope is {@link #DESKTOP_SCOPE}, it means custom attributes shared * by components from the same desktopas this one's. * * @param scope {@link #COMPONENT_SCOPE}, {@link #SPACE_SCOPE},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -