ZK----别人经典1

http://tsinglongwu.iteye.com/category/131795

 

1. zul页面读取国际化资源:
1) 准备资源:i3-label.properties(如果为制定默认该文件)、i3-label_zh_CN.properties(其中i3-label为固定格式),放在WEB-INF目录下;
2) 在zul页面头部添加如下代码

Zul代码 复制代码 收藏代码
  1. <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>

3) 使用:

Zul代码 复制代码 收藏代码
  1. <label value="${c:l('label.system.name')}"/>
<label value="${c:l('label.system.name')}"/>



2. Java读取国际化资源:

Java代码 复制代码 收藏代码
  1. import org.zkoss.util.resource.Labels;
  2. String str = Labels.getLabel(key);
import org.zkoss.util.resource.Labels;

String str = Labels.getLabel(key);


在页面中通过按钮切换语言:

Java代码 复制代码 收藏代码
  1. Locale locale=Locales.getLocale((String)language.getSelectedItem().getValue()); //假如(String)language.getSelectedItem().getValue()为‘zh_CN’
  2. session.setAttribute("px_preferred_locale", locale);
  3. execution.sendRedirect(execution.getContextPath()+ "/login.zul");
		Locale locale=Locales.getLocale((String)language.getSelectedItem().getValue()); //假如(String)language.getSelectedItem().getValue()为‘zh_CN’
		session.setAttribute("px_preferred_locale", locale);
		execution.sendRedirect(execution.getContextPath()+ "/login.zul");



3. 获取zul页面组件:

Java代码 复制代码 收藏代码
  1. //zul:
  2. <window id="win">
  3. <Listbox id="lb"/>
  4. </window>
  5. //java:
  6. Component component= Path.getComponent("/win/lb");
//zul:
<window id="win"> 
    <Listbox id="lb"/>
</window>

//java:
Component component= Path.getComponent("/win/lb");



4. 数据绑定管理器重复绑定的异常处理:
在执行代码:

Java代码 复制代码 收藏代码
  1. Executions.createComponents(newZulUri, parentWin, null);
Executions.createComponents(newZulUri, parentWin, null);

时,parentWin所在zul页面使用了数据绑定功能(当前页没有):

Zul代码 复制代码 收藏代码
  1. <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>

执行时出现异常:
"org.zkoss.zk.ui.UiException: Page is already covered by another Data Binder. Cannot be covered by this Data Binder again."

----解决:这是由于数据绑定管理器没有指定目标组件,如果有多个parentWin页面同时使用数据绑定管理器的话将会出现重复绑定的情况(具体原因还没搞清,欢迎高手指点:)。因此可以为每个使用数据绑定的页面添加绑定目标:

Zul代码 复制代码 收藏代码
  1. <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./win"?>
  2. <window id="win">
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"  root="./win"?>

<window id="win">



5. 如何让Messagebox.show()事件生效:
在WEB-INF/zk.xml中有以下配置:

Java代码 复制代码 收藏代码
  1. <system-config>
  2. <disable-event-thread>true|false</disable-event-thread>
  3. </system-config>
<system-config>
    <disable-event-thread>true|false</disable-event-thread>
</system-config>


[Default: true (disabled) for ZK 5 ad later; false (enabled) for ZK 2.x and 3x]

引用
It specifies whether to disable the use of the event processing thread. If disabled, no event processing thread will be used at all. In other words, all events are processed in the same thread that serves HTTP request (so called Servlet thread) directly.

For better performance (and better compatible with other frameworks), it is recommended to disable the use of the event processing thread. For more information, please refer to ZK Developer's Reference.

Enable the event thread only if the project does not need to integrate other frameworks (such as Spring), uses Messagebox and modal windows a lot, and does not have a lot of concurrent users.



如果设置为true,则Messagebox.show()需要添加事件监听器参数,如:

Java代码 复制代码 收藏代码
  1. Messagebox.show("Remove record?", "Question", Messagebox.OK
  2. | Messagebox.CANCEL, Messagebox.QUESTION,
  3. new EventListener() {
  4. @Override
  5. publicvoid onEvent(Event event) throws Exception {
  6. if (((Integer) event.getData()).intValue() == Messagebox.OK) {
  7. System.out.println("Messagebox.OK selected!");
  8. return;
  9. } else {
  10. System.out
  11. .println("Messagebox.CANCEL selected!");
  12. return;
  13. }
  14. }
  15. });
Messagebox.show("Remove record?", "Question", Messagebox.OK
					| Messagebox.CANCEL, Messagebox.QUESTION,
					new EventListener() {
						@Override
						public void onEvent(Event event) throws Exception {
							if (((Integer) event.getData()).intValue() == Messagebox.OK) {
								System.out.println("Messagebox.OK selected!");
								return;
							} else {
								System.out
										.println("Messagebox.CANCEL selected!");
								return;
							}
						}
					});


6. 给弹出窗口设置参数:
例如:

Java代码 复制代码 收藏代码
  1. Map<String, String> arg = new HashMap<String, String>();
  2. arg.put("hostGroupId", hostGroupId);
  3. arg.put("hostGroupType", hostGroupType);
  4. Window wnd = (Window) Executions.createComponents("/pages/hostMan/hostAdd.zul", null, arg);
  5. wnd.doModal();
Map<String, String> arg = new HashMap<String, String>();
arg.put("hostGroupId", hostGroupId);
arg.put("hostGroupType", hostGroupType);
Window wnd = (Window) Executions.createComponents("/pages/hostMan/hostAdd.zul", null, arg);
wnd.doModal();


取值方式1:窗口弹出后读取参数需要写在渲染方法public void afterCompose() {}中,如:

Java代码 复制代码 收藏代码
  1. hostGroupId = (String) Executions.getCurrent().getArg().get("hostGroupId");
hostGroupId = (String) Executions.getCurrent().getArg().get("hostGroupId");


取值方式2:

Java代码 复制代码 收藏代码
  1. Window viewWin = (Window) Executions.createComponents(
  2. "pages/reportView.zul", IndexWin.this, argMap);
Window viewWin = (Window) Executions.createComponents(
     "pages/reportView.zul", IndexWin.this, argMap);


java类中:

Java代码 复制代码 收藏代码
  1. Map argMap = this.getDesktop().getExecution().getArg();
Map argMap = this.getDesktop().getExecution().getArg();


7. 其它技术点:

引用
1,修改zk中默认字体大小
2,zk中添加网站头像(即favicon.ico)
3,borderlayout布局组件的使用
4,自定义宏的使用
5,tree组件的使用
6,grid的使用,以及偶数行着色显示
7,forward属性的使用
8,基于注解的数据绑定
1)org.zkoss.zkplus.databind.AnnotateDataBinderInit类的使用
2)zk注解中类型转换器的使用(TypeConverter)
3)注解中设置别名
4)调用service,异步更新视图
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值