Include"

From Documentation
Line 28: Line 28:
 
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.
 
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'''
+
= Example =
 +
<source lang="xml" >
 +
<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>
 +
</source>
 +
 
 +
=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.
 
There are two ways to pass values to the included page. First, you can pass them with the query string.
  
Line 49: Line 59:
 
  ${requestScope.some}
 
  ${requestScope.some}
  
 +
= Refresh Inner Pages Only =
 +
First, use '''include''' component and specifies the '''src''' attribute to include  whatever page you want (ZK, JSP, JSF or whatever) inside a ZK page. Second, you can dynamically change it by changing the '''src''' attribute. e.g. The following code would change the inner page from hello.zul to byebye.zul when an end user press the Bye! button.
 +
 +
<source lang="xml">
 +
<include id="inner" src="hello.zul"/>
 +
<button label="Bye!" onClick='inner.src = "byebye.zul"'/>
 +
</source>
 +
 +
If you simply want to ''reload'' the same page(and not to change to another page), you have to set the '''src''' attribute to null first; then set the '''src''' attribute back to what it was. Because ZK optimizes operations, set same value to the same attribute would be deemed doing nothing. e.g. The following code would refresh the hello.zul page when an end user press the Reload button.
 +
 +
<source lang="xml">
 +
<include id="inner" src="hello.zul"/>
 +
<button id="reload" label="Reload" onClick="String tmp=inner.src; inner.src=null; inner.src=tmp;"/>
 +
</source>
  
= Example =
+
Another way is to invalidate the "include" element:
<source lang="xml" >
+
<source lang="xml">
<window title="include demo" border="normal" width="300px">
+
<include id="inner" src="hello.zul"/>
Hello, World!
+
<button id="reload" label="Reload" onClick="inner.invalidate();"/>
<include src="/userguide/misc/includedHello.zul" />
 
<include src="/html/frag.html?some=any" />
 
<include src="mypage" argument="${anyValue}" other="${anotherValue}" />
 
</window>
 
 
</source>
 
</source>
 +
  
 
=Properties=
 
=Properties=

Revision as of 22:25, 3 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.

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>

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}

Refresh Inner Pages Only

First, use include component and specifies the src attribute to include whatever page you want (ZK, JSP, JSF or whatever) inside a ZK page. Second, you can dynamically change it by changing the src attribute. e.g. The following code would change the inner page from hello.zul to byebye.zul when an end user press the Bye! button.

<include id="inner" src="hello.zul"/>
<button label="Bye!" onClick='inner.src = "byebye.zul"'/>

If you simply want to reload the same page(and not to change to another page), you have to set the src attribute to null first; then set the src attribute back to what it was. Because ZK optimizes operations, set same value to the same attribute would be deemed doing nothing. e.g. The following code would refresh the hello.zul page when an end user press the Reload button.

<include id="inner" src="hello.zul"/>
<button id="reload" label="Reload" onClick="String tmp=inner.src; inner.src=null; inner.src=tmp;"/>

Another way is to invalidate the "include" element:

<include id="inner" src="hello.zul"/>
<button id="reload" label="Reload" onClick="inner.invalidate();"/>


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/03


Version Date Content
     



Last Update : 2010/12/03

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