ZK學習筆記

[color=brown]1. zul頁面讀取國際化資源:[/color]
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')}"/>


[color=brown]2. Java讀取國際化資源:[/color]

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");


[color=brown]3. 獲取zul頁面組件:[/color]

//zul:
<window id="win">
<Listbox id="lb"/>
</window>

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


[color=brown]4. 數據綁定管理器重複綁定的異常處理:[/color]
在執行代碼:
Executions.createComponents(newZulUri, parentWin, null);
時,parentWin所在zul頁面使用了數據綁定功能(當前頁沒有):
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
執行時出現異常:
"[i]org.zkoss.zk.ui.UiException: Page is already covered by another Data Binder. Cannot be covered by this Data Binder again.[/i]"

----解決:這是由於數據綁定管理器沒有指定目標組件,如果有多個parentWin頁面同時使用數據綁定管理器的話將會出現重複綁定的情況(具體原因還沒搞清,歡迎高手指點:)。因此可以爲每個使用數據綁定的頁面添加綁定目標:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"  root="./win"?>

<window id="win">


[color=brown]5. 如何讓Messagebox.show()事件生效:[/color]
在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]

[quote]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. [/quote]

如果設置爲true,則Messagebox.show()需要添加事件監聽器參數,如:
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;
}
}
});

[color=brown]6. 給彈出窗口設置參數:[/color]
例如:
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();

[color=brown]7. 其它技術點:[/color]
[quote]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,異步更新視圖[/quote]以上參考:[url]http://zkoss.group.iteye.com/group/blog/620821[/url]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章