Include"

From Documentation
Line 84: Line 84:
 
<source lang="xml">
 
<source lang="xml">
 
<window title="demo" border="normal">
 
<window title="demo" border="normal">
<include mode="instant" src="include.zul" />
+
<include mode="defer" src="include.zul" />
 
</window>
 
</window>
 
</source>
 
</source>
Line 96: Line 96:
 
<source lang="xml">
 
<source lang="xml">
 
<window title="demo" border="normal">
 
<window title="demo" border="normal">
<include mode="defer" src="include.zul" />
+
<include mode="auto" src="include.zul" />
 
</window>
 
</window>
 
</source>
 
</source>

Revision as of 04:41, 1 December 2010

Include

Employment/Purpose

The include component is used to include the output generated by another servlet. The servlet could be anything including JSF, JSP and even another ZUML page.

<window title="include demo" border="normal" width="300px">
	Hello, World!
	<include src="/userguide/misc/includedHello.zul" />
	<include src="/html/frag.html?some=any" />
	<include src="mypage" argument="${anyValue}" other="${anotherValue}" />
</window>

Like all other properties, you could dynamically change the src attribute to include the output from a different servlet at the run time.

If the included output is another ZUML, developers are allowed to access components in the included page as if they are part of the containing page.

If the include component is used to include a ZUML page, the included page will become part of the desktop. However, the included page is not visible until the request is processed completely. In other words, it is visible only in the following events, triggered by user or timer.

The reason is that the include component includes a page as late as the Rendering phase. On the other hand, zscript takes place at the Component Creation phase, and onCreate takes place at the Event Processing Phase. They both execute before the inclusion.

Pass Values to the Included Page There are two ways to pass values to the included page. First, you can pass them with the query string.

 <include src="mypage?some=something"/>

Then, in the included page, you can access them with the getParameter method of the Execution interface or the ServletRequest interface. In EL expressions (of the included page), you can use the param variable to access them. However, you can only pass String-typed values with the query string.

${param.some}

Alternatively, we can pass any kind of values with the so-called dynamic properties by use of the setDynamicProperty method or, in ZUL, a dynamic property as follows:

 <include src="mypage" some="something" another="${expr}"/>

With the dynamic properties, you can pass non-String-typed values. In the included page, you can access them with the getAttribute method of the Execution interface or the ServletRequest interface. In EL expressions (of the included page), you can use the requestScope variable to access them.

${requestScope.some}


Example

<window title="include demo" border="normal" width="300px">
	Hello, World!
	<include src="/userguide/misc/includedHello.zul" />
	<include src="/html/frag.html?some=any" />
	<include src="mypage" argument="${anyValue}" other="${anotherValue}" />
</window>

Properties

Modes

When using the include component within ZUL files we can experience problems if the included file's components need to be accessed before they have been created and rendered. There are now three include modes, defer, instant and auto. The behavior of the include tag prior to version 5.0.0 is the same as the default mode, auto.

Instant

The instant mode allows pages to be created immediately using the Execution.createComponents(String, Component, Map) function, meaning that they are instantly accessible to the user and therefore no confusion or problems arise due to the initialization order.

The code below demonstrates how to use the instant mode:

<window title="demo" border="normal">
	<include mode="instant" src="include.zul" />
</window>

Defer

The defer mode allows the page to be included by servlet container (the include method of javax.servlet.RequestDispatcher) in the render phase (i.e., after all components are created). The page can be any servlet; not limited to a ZUML page. The code below demonstrates how to use the defer mode:

<window title="demo" border="normal">
	<include mode="defer" src="include.zul" />
</window>

Auto

The auto mode selects which mode is most suited for the inclusion type. If the inclusion is a ZUL file then the instant mode will be used and if not the defer mode will be.

The code below demonstrates how to use the auto mode:

<window title="demo" border="normal">
	<include mode="auto" src="include.zul" />
</window>

Note: the auto mode is by default in ZK 5 version.

Making defer your default mode

By default, the auto mode is assumed, but if you want to use it as same as ZK 3.x version, you can set the defer mode as default by including a library variable in your zk.xml configuration file.

The XML below demonstrates how to do this:

<library-property>
        <name>org.zkoss.zul.include.mode</name>
 	<value>defer</value>
</library-property>

Supported Events

Name
Event Type
None None

Supported Children

*NONE

Use Cases

Version Description Example Location
     

Version History

Last Update : 2010/12/01


Version Date Content
     



Last Update : 2010/12/01

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.