ZK学习笔记
1. zul页面读取国际化资源:
1) 准备资源:i3-label.properties(如果为制定默认该文件)、i3-label_zh_CN.properties(其中i3-label为固定格式),放在WEB-INF目录下;
2) 在zul页面头部添加如下代码
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>3) 使用:
<label value="${c:l('label.system.name')}"/>2. Java读取国际化资源:
import org.zkoss.util.resource.Labels;String str = Labels.getLabel(key);
在页面中通过按钮切换语言:
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页面组件:
//zul:<window id="win"> <Listbox id="lb"/></window>//java:Component component= Path.getComponent("/win/lb");4. 数据绑定管理器重复绑定的异常处理:
在执行代码:
Executions.createComponents(newZulUri, parentWin, null);时,parentWin所在zul页面使用了数据绑定功能(当前页没有):
<?init ?>执行时出现异常:
"org.zkoss.zk.ui.UiException: Page is already covered by another Data Binder. Cannot be covered by this Data Binder again."
----解决:这是由于数据绑定管理器没有指定目标组件,如果有多个parentWin页面同时使用数据绑定管理器的话将会出现重复绑定的情况(具体原因还没搞清,欢迎高手指点:)。因此可以为每个使用数据绑定的页面添加绑定目标:
<?init root="./win"?><window id="win">
5. 如何让Messagebox.show()事件生效:
在WEB-INF/zk.xml中有以下配置:
<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]
Messagebox.show("Remove record?", "Question", Messagebox.OK| Messagebox.CANCEL, Messagebox.QUESTION,new EventListener() {@Overridepublic 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. 给弹出窗口设置参数:
例如:
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() {}中,如:
hostGroupId = (String) Executions.getCurrent().getArg().get("hostGroupId");取值方式2:
Window viewWin = (Window) Executions.createComponents( "pages/reportView.zul", IndexWin.this, argMap);
java类中:
Map argMap = this.getDesktop().getExecution().getArg();
7. 其它技术点:
<window id="win1"><label id="labelX" value="@{val}"/></window><window id="win2"><label id="labelX" value="@{val}"/></window>
故需指定目标<window id="win1"><label id="labelX" value="@{val}"/></window><window id="win2"><label id="labelX" value="@{val}"/></window>
故需指定目标
只知道有人解释说“it'll append the binder in the page”,呵呵,原来是这样,受教了。。