|
|
(One intermediate revision by one other user not shown) |
Line 2: |
Line 2: |
| | | |
| == Overview == | | == Overview == |
− | For scripts embedded in a ZUML page, there are a set of implicit objects that enable developers to access components more efficiently. It's also a mechanism to pass data inter page, application. These objects are available to the Java codes included by the <tt>zscript</tt> element and the attributes for specifying event listeners. They are also available to EL expressions. | + | For scripts embedded in a ZUML page, there are a set of implicit objects that enable developers to access components more efficiently. It's also a mechanism to pass data inter page, application. These objects are available to the Java codes included by the <code>zscript</code> element and the attributes for specifying event listeners. They are also available to EL expressions. |
| | | |
− | For example, <tt>self</tt> is an instance of <javadoc type="interface">org.zkoss.zk.ui.Component</javadoc> to represent the component being processing. In the following example, you could identify the component in an event listener by <tt>self</tt>. | + | For example, <code>self</code> is an instance of <javadoc type="interface">org.zkoss.zk.ui.Component</javadoc> to represent the component being processing. In the following example, you could identify the component in an event listener by <code>self</code>. |
| | | |
| <source lang="xml" > | | <source lang="xml" > |
Line 10: |
Line 10: |
| </source> | | </source> |
| | | |
− | Similarly, <tt>event</tt> is the current event being processed by an event listener. Thus, the above statement is equivalent to | + | Similarly, <code>event</code> is the current event being processed by an event listener. Thus, the above statement is equivalent to |
| | | |
| <source lang="xml" > | | <source lang="xml" > |
Line 17: |
Line 17: |
| | | |
| | | |
− | == List of Implicit Objects ==
| + | {{ZKDevelopersGuideHeadingToc}} |
| | | |
− | {| border="1"
| |
− | ! <center>Object Name</center>
| |
− | ! <center>Type</center>
| |
− | ! <center>Description</center>
| |
− |
| |
− | |-
| |
− | | self
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/Component.html <javadoc type="interface">org.zkoss.zk.ui.Component</javadoc>]
| |
− |
| |
− | |The component itself.
| |
− |
| |
− | |-
| |
− | | spaceOwner
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/idspace.html <javadoc type="interface">org.zkoss.zk.ui.IdSpace</javadoc>]
| |
− |
| |
− | |The space owner of this component. It is the same as <javadoc type="interface">self.spaceOwner</javadoc>.
| |
− |
| |
− | |-
| |
− | | page
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/page.html <javadoc type="interface">org.zkoss.zk.ui.Page</javadoc>]
| |
− |
| |
− | |The page. It is the same as <tt>self.page</tt>.
| |
− |
| |
− | |-
| |
− | | desktop
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/desktop.html <javadoc type="interface">org.zkoss.zk.ui.Desktop</javadoc>]
| |
− |
| |
− | |The desktop. It is the same as <tt>self.desktop</tt>.
| |
− |
| |
− | |-
| |
− | | execution
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/execution.html <javadoc type="interface">org.zkoss.zk.ui.Execution</javadoc>]
| |
− |
| |
− | |The current execution.
| |
− |
| |
− | |-
| |
− | | session
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/session.html <javadoc type="interface">org.zkoss.zk.ui.Session</javadoc>]
| |
− |
| |
− | |The session.
| |
− |
| |
− | |-
| |
− | | application
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/webapp.html <javadoc type="interface">org.zkoss.zk.ui.WebApp</javadoc>]
| |
− |
| |
− | |The Web application.
| |
− |
| |
− | |-
| |
− | | componentScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the component. It is the same as the <tt>getAttributes</tt> method in the <javadoc type="interface">org.zkoss.zk.ui.Component</javadoc> interface.
| |
− |
| |
− | |-
| |
− | | spaceScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the ID space containing this component.
| |
− |
| |
− | |-
| |
− | | pageScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the page. It is the same as the <tt>getAttributes</tt> method in the <javadoc type="interface">org.zkoss.zk.ui.Page</javadoc> interface.
| |
− |
| |
− | |-
| |
− | | desktopScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the desktop. It is the same as the <tt>getAttributes</tt> method in the <javadoc type="interface">org.zkoss.zk.ui.Desktop</javadoc> interface.
| |
− |
| |
− | |-
| |
− | | sessionScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the session. It is the same as the <tt>getAttributes</tt> method in the <javadoc type="interface">org.zkoss.zk.ui.Session</javadoc> interface.
| |
− |
| |
− | |-
| |
− | | applicationScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the web application. It is the same as the <tt>getAttributes</tt> method in the <javadoc type="interface">org.zkoss.zk.ui.WebApp</javadoc> interface.
| |
− |
| |
− | |-
| |
− | | requestScope
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes defined in the request. It is the same as the <tt>getAttributes</tt> method in the <javadoc type="interface">org.zkoss.zk.ui.Execution</javadoc> interface.
| |
− |
| |
− | |-
| |
− | | param
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |A map of attributes passed by the query string. Please refer to section [[Work_with_HTML_Tags#Pass_Values_to_the_Included_Page|Pass Values to the Included Page]] for example.
| |
− |
| |
− | |-
| |
− | | arg
| |
− | | <tt>java.util.Map</tt>
| |
− |
| |
− | |The <tt>arg</tt> argument passed to the <tt>createComponents</tt> method in the <javadoc>org.zkoss.zk.ui.Executions</javadoc> class. It is never <tt>null</tt>.
| |
− |
| |
− | It is the same as <tt>self.desktop.execution.arg</tt>.
| |
− |
| |
− | Notice that <tt>arg</tt> is available only when creating the components for the included page (the first argument of <tt>createComponents</tt>). On the other hand, all events, including <tt>onCreate</tt>, are processed later. Thus, if you want to access <tt>arg</tt> in the <tt>onCreate</tt>'s listener, use the <tt>getArg</tt> method of the <javadoc>org.zkoss.zk.ui.event.CreateEvent</javadoc> class.
| |
− |
| |
− |
| |
− |
| |
− | |-
| |
− | | each
| |
− | | <tt>java.lang.Object</tt>
| |
− |
| |
− | |The current item of the collection being iterated, when ZK evaluates an iterative element. An iterative element is an element with the forEach attribute.
| |
− |
| |
− | |-
| |
− | | forEachStatus
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/util/foreachstatus.html <javadoc type="interface">org.zkoss.zk.ui.util.ForEachStatus</javadoc>]
| |
− |
| |
− | |The status of an iteration. ZK exposes the information relative to the iteration taking place when evaluating the iterative element.
| |
− |
| |
− | |-
| |
− | | event
| |
− | | [http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/event/event.html <javadoc>org.zkoss.zk.ui.event.Event</javadoc>] or derived
| |
− |
| |
− | |The current event. Available for the event listener only.
| |
− |
| |
− | |}
| |
− |
| |
− |
| |
− | Implicit objects provides many useful methods for web application. You can click the hyperlink to see the java doc of each implicit object.
| |
− |
| |
− | == Information about Request and Execution ==
| |
− | An execution of a client request (e.g., ServletRequest). When a request sent from a client, the server constructs a Execution object to hold execution relevant info, and then serves the request through this execution.
| |
− |
| |
− | A client request, e.g., HttpServletRequest, might consist of multiple ZK request (AuRequest). However, these ZK requests must target the same desktop of pages (Page).
| |
− |
| |
− | The <javadoc type="interface">org.zkoss.zk.ui.Execution</javadoc> interface provides information about the current execution, such as the request parameters. To get the current execution, you could simply use the <tt>getCurrent</tt> method in the <javadoc>org.zkoss.zk.ui.Executions</javadoc> class. It's a static class.
| |
− |
| |
− | The following example will show the server name.
| |
− | <source lang="xml" >
| |
− | <window>
| |
− | <zscript>
| |
− | String sn = Executions.getCurrent().getServerName();
| |
− | </zscript>
| |
− | The server is: ${sn}
| |
− | </window>
| |
− | </source>
| |
− |
| |
− | ==Life cycle of page, execution, desktop, session, application==
| |
− |
| |
− | From small scope to big:
| |
− | *page
| |
− | : A single page.
| |
− | *execution<ref><tt>execution</tt> in ZK is a wrapper of <tt>request</tt> in JSP </ref>
| |
− | : Processing a request from client side. It can cross pages.
| |
− | *desktop
| |
− | : All pages serving the same URL, for one browser tab.
| |
− | *session
| |
− | : From user visit the web to user leave or timeout. All following pages are related to same session.
| |
− | *application
| |
− | : From the application service start to stop. It is cross session, cross users.
| |
− |
| |
− | Note that, if you press "F5" to refresh the web page, it's a different desktop, but the same session.
| |
− |
| |
− | ==About xxxScope==
| |
− | Each xxxScope is a map of attribute of certain component. You can use it as a temporary space to save and retrieve data. It's a mechanism to realize communication between pages, applications. You have to understand each component's life cycle, to decide which scope you should use. In most cases, you should use <tt>session</tt>.
| |
− | <tt>setAttribute</tt>, and <tt>getAttribute</tt> are the api to set and get variable in certain xxxScope.
| |
− |
| |
− |
| |
− | '''Note'''
| |
− | <references/>
| |
− |
| |
− | ==See Also==
| |
− | :For more information, please refer to [http://books.zkoss.org/wiki/ZK_Component_Reference developer's reference]. The concept of implicit object is much like [http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro7.html#70899 JSP].
| |
− | :[http://books.zkoss.org/wiki/ZK_ZUML_Reference/The_ZK_User_Interface_Markup_Language/Implicit_Objects Most used api for Implicit Objects and Static Classes] -- includes Executions, Path, Clients
| |
− |
| |
− | == Quiz ==
| |
− |
| |
− | 1.Find Out the api of implicit object, that can
| |
− |
| |
− | *Creates components from the specified page definition
| |
− |
| |
− | *Sets a bookmark to this desktop.
| |
− |
| |
− | *Returns the Internet Protocol (IP) address of the interface on which the first request was received (and creates this session).
| |
− |
| |
− | 2.It's common to include another <tt>page</tt> inside current <tt>page</tt>, and it's a common need to pass variable between these 2 pages. Please refer to [[Work_with_HTML_Tags#The_include_Component | The include component]]. Use <tt>session.setAttribute</tt> and <tt>getAttribute</tt> to pass the value of <tt>passed</tt> between following 2 zul pages.
| |
− |
| |
− | helloworld.zul
| |
− | <source lang="xml" >
| |
− | <window>
| |
− | <label id="passed" value="Hello, World!"/>
| |
− | <include src="included.zul"/>
| |
− | </window>
| |
− | </source>
| |
− |
| |
− | And included.zul:
| |
− | <source lang="xml" >
| |
− | <window>
| |
− | The value of passed is
| |
− | </window>
| |
− | </source>
| |
| | | |
| {{ ZKDevelopersGuidePageFooter}} | | {{ ZKDevelopersGuidePageFooter}} |