http://tsinglongwu.iteye.com/category/131795
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" ?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
3) 使用:
- <label value="${c:l('label.system.name')}"/>
<label value="${c:l('label.system.name')}"/>
2. Java读取国际化资源:
- import org.zkoss.util.resource.Labels;
- String str = Labels.getLabel(key);
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");
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");
//zul: <window id="win"> <Listbox id="lb"/> </window> //java: Component component= Path.getComponent("/win/lb");
4. 数据绑定管理器重复绑定的异常处理:
在执行代码:
- Executions.createComponents(newZulUri, parentWin, null);
Executions.createComponents(newZulUri, parentWin, null);
时,parentWin所在zul页面使用了数据绑定功能(当前页没有):
- <?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页面同时使用数据绑定管理器的话将会出现重复绑定的情况(具体原因还没搞清,欢迎高手指点:)。因此可以为每个使用数据绑定的页面添加绑定目标:
- <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./win"?>
- <window id="win">
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./win"?> <window id="win">
5. 如何让Messagebox.show()事件生效:
在WEB-INF/zk.xml中有以下配置:
- <system-config>
- <disable-event-thread>true|false</disable-event-thread>
- </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]
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()需要添加事件监听器参数,如:
- Messagebox.show("Remove record?", "Question", Messagebox.OK
- | Messagebox.CANCEL, Messagebox.QUESTION,
- new EventListener() {
- @Override
- publicvoid 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;
- }
- }
- });
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. 给弹出窗口设置参数:
例如:
- 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();
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");
hostGroupId = (String) Executions.getCurrent().getArg().get("hostGroupId");
取值方式2:
- Window viewWin = (Window) Executions.createComponents(
- "pages/reportView.zul", IndexWin.this, argMap);
Window viewWin = (Window) Executions.createComponents( "pages/reportView.zul", IndexWin.this, argMap);
java类中:
- Map argMap = this.getDesktop().getExecution().getArg();
Map argMap = this.getDesktop().getExecution().getArg();
7. 其它技术点:
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,异步更新视图