⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 b30-1892484.zul

📁 ZK是一个Ajax Java Web框架
💻 ZUL
字号:
<?xml version="1.0" encoding="UTF-8"?>

<!--
serialize2.zul

{{IS_NOTE
	Purpose:
		Test Serializable with Live Data
	Description:
		
	History:
		Tue May 29 17:38:37     2007, Created by tomyeh
}}IS_NOTE

Copyright (C) 2007 Potix Corporation. All Rights Reserved.

{{IS_RIGHT
}}IS_RIGHT
-->
<window title="Serialize Live Data" border="normal">
	<zscript>
	import java.io.*;
	import org.zkoss.zkdemo.test2.tree.TreeModelA;

	int cnt = 0;
	Object l;
	
	void serialize(Component from) {
		ByteArrayOutputStream boa = new ByteArrayOutputStream();
		new ObjectOutputStream(boa).writeObject(from);
		byte[] bs = boa.toByteArray();
		l = new ObjectInputStream(new ByteArrayInputStream(bs)).readObject();
		l.setId("dst" + ++cnt);
		l.setParent(vb);
		new Label(bs.length+" bytes copied").setParent(vb);
	}
	
		//An ArrayList is created to be the root of tree
		ArrayList mother = new ArrayList();
		
		//Assign children to root "mother"
		mother.add("Andy");
		mother.add("Davis");
		mother.add("Matter");
		mother.add("Kitty");
		
		//TreeModelA class is contructed, only the root "mother" of tree is passed to its constructor.
		TreeModelA tma = new TreeModelA(mother);
		
		ArrayList childnew = new ArrayList();
		childnew.add("Clinton");
		childnew.add("Obama");
		public void replace(){
			Object[] data = {childnew};
			tma.set(mother,2,2,data);
		}
		
		ArrayList childnew2 = new ArrayList();
		childnew2.add("Clinton");
		childnew2.add("Obama");
		public void replace2(){
			Tree t = (Tree)l;
			TreeModelA tma2 = (TreeModelA)t.getModel();
			Object[] data = {childnew2};
			tma2.set(tma2.getRoot(),2,2,data);
		}
	
	</zscript>
	<vbox>
	<label value="1.Click on serialize tree, there should be 2 trees" />
	<label value='2.Click on "Replace", only upper tree is updated, lower one is NOT' />
	<label value='3.Click on "Relace 2", only the lower tree is updated' />
	</vbox>
	<vbox id="vb">
		<tree model="${tma}" id="tree" >
		</tree>
		<button label="Replace" onClick="replace();" />
		<button label="Replace 2" onClick="replace2();" />
	</vbox>

	<button label="serialize tree" onClick="serialize(tree)"/>
</window>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -