ZATS ConnectAsIncluded"

From Documentation
m (correct highlight (via JWB))
 
(13 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
{{Template:UnderConstruction}}
 
{{ZATSEssentialsPageHeader}}
 
{{ZATSEssentialsPageHeader}}
__TOC__
 
 
  Since 1.1.0
 
  Since 1.1.0
  
  
ZK provides the <javadoc>org.zkoss.zul.Include</javadoc> component allows us to include or reuse ZUL page or others.<ref>For more details, please refer to [[ZK_Developer%27s_Reference/UI_Composing/ZUML/Include]] and [[ZK_Component_Reference/Essential_Components/Include]]</ref> We can directly test a ZUL page which is included by outer pages; just connect to such ZUL through the <tt>Client.connect(String)</tt> method as usual.
+
ZK provides the <javadoc>org.zkoss.zul.Include</javadoc> component<ref>For more details, please refer to [[ZK_Developer%27s_Reference/UI_Composing/ZUML/Include]] and [[ZK_Component_Reference/Essential_Components/Include]]</ref> and <javadoc method="createComponents(String, Component, Map)">org.zkoss.zk.ui.Execution</javadoc> method<ref>For more details, please refer to [[ZK_Developer%27s_Reference/UI_Composing/ZUML/Load_ZUML_in_Java]]</ref> to include and reuse ZUL pages or others. In ZATS Mimic, we can test ZUL pages which are included by outer pages directly; just connect to such ZUL pages through the <code>Client.connect(String)</code> method as usual.  
  
= Connect as Included =
+
= Test Included ZUL Pages with Arguments =
Sometimes, we pass some arguments to included ZUL pages for flexibility purpose, and the arguments can be retrieved from the implicit objects [[ZUML_Reference/EL_Expressions/Implicit_Objects/arg|arg]] inside of ZUL pages. ZATS Mimic introduces another connecting method <tt>Client.connectAsIncluded(String, Map<String, Object>)</tt> for above case. Following is a typical example of included ZUL page with arguments:
+
Sometimes, we pass some arguments to included ZUL pages for flexibility, and the arguments can be retrieved from the implicit objects [[ZUML_Reference/EL_Expressions/Implicit_Objects/arg|arg]] in such ZUL pages. ZATS Mimic introduces another connecting method <code>Client.connectAsIncluded(String, Map<String, Object>)</code> for above case. Following is a typical example of connecting to a included ZUL page with specific arguments:
  
 
'''included.zul'''
 
'''included.zul'''
<source lang="xml" high="2">
+
<source lang="xml" highlight="2">
 
<zk>
 
<zk>
 
<label id="msg" value="${arg.message }" />
 
<label id="msg" value="${arg.message }" />
Line 19: Line 19:
  
 
'''Test.java'''
 
'''Test.java'''
<source lang="java" start="10" high="12, 13, 14">
+
<source lang="java" start="10" highlight="12, 13, 15">
 
@Test
 
@Test
 
public void test() {
 
public void test() {
Line 25: Line 25:
 
args.put("message", "Hello world!");
 
args.put("message", "Hello world!");
 
Client client = Zats.newClient();
 
Client client = Zats.newClient();
DesktopAgent desktop = client.connectAsIncluded("/~./basic/included.zul", args);
+
DesktopAgent desktop = client.connectAsIncluded("/included.zul", args);
 
Label msg = desktop.query("#msg").as(Label.class);
 
Label msg = desktop.query("#msg").as(Label.class);
 
Assert.assertEquals("Hello world!", msg.getValue());
 
Assert.assertEquals("Hello world!", msg.getValue());
 
}
 
}
 
</source>
 
</source>
* '''Line 12-13''':  
+
* '''Line 12-13''': Prepare arguments for included ZUL page.
* '''Line 14''':
+
* '''Line 15''': Connect to included ZUL page with arguments.
  
  
 
'''Notes'''
 
'''Notes'''
 
<references/>
 
<references/>
 
 
== Including with Defer Mode ==
 
There is no different between testing a normal ZUL or testing a included ZUL directly. We can just use the normal <tt>Client.connect(String url)</tt> method to connect ZUL.
 
  
  
 
{{ZATSEssentialsPageHeader}}
 
{{ZATSEssentialsPageHeader}}
 
{{ZATSEssentialsPageFooter}}
 
{{ZATSEssentialsPageFooter}}

Latest revision as of 02:58, 20 January 2022

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

aowang



Since 1.1.0


ZK provides the Include component[1] and Execution.createComponents(String, Component, Map) method[2] to include and reuse ZUL pages or others. In ZATS Mimic, we can test ZUL pages which are included by outer pages directly; just connect to such ZUL pages through the Client.connect(String) method as usual.

Test Included ZUL Pages with Arguments

Sometimes, we pass some arguments to included ZUL pages for flexibility, and the arguments can be retrieved from the implicit objects arg in such ZUL pages. ZATS Mimic introduces another connecting method Client.connectAsIncluded(String, Map<String, Object>) for above case. Following is a typical example of connecting to a included ZUL page with specific arguments:

included.zul

<zk>
	<label id="msg" value="${arg.message }" />
</zk>
  • Line 2: The value is retrieved from arguments.


Test.java

@Test
public void test() {
	Map<String, Object> args = new HashMap<String, Object>();
	args.put("message", "Hello world!");
	Client client = Zats.newClient();
	DesktopAgent desktop = client.connectAsIncluded("/included.zul", args);
	Label msg = desktop.query("#msg").as(Label.class);
	Assert.assertEquals("Hello world!", msg.getValue());
}
  • Line 12-13: Prepare arguments for included ZUL page.
  • Line 15: Connect to included ZUL page with arguments.


Notes


aowang




Last Update : 2022/01/20

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