http://www.pichelhofer.at/ZKDemo/src/DateUser.java.html
<listcell label="@{employee.hireDate, converter='org.zkforge.converters.DateUser'}"/>
<listcell label="@{employee.hireDate, converter='org.zkforge.converters.DateUser'}"/>
public void onClick$selectedBtn(Event e) throws Exception{
Employee selected =(Employee)win.getVariable("selected", true);
if (selected != null){
alert(selected.firstName);
}
}
public void onClick$clearBtn(Event e) throws Exception{
empData = null;
empListbox.unsetVariable("selected", true);
binder = (AnnotateDataBinder)page.getVariable("binder");
binder.loadAll();
}
public void onClick$clearSelBtn(Event e) throws Exception{
empListbox.unsetVariable("selected", true);
binder = (AnnotateDataBinder)page.getVariable("binder");
binder.loadAll();
}
<window id="win" title="MVCサンプル" border="normal" width="300px" apply="Controler1">
<hbox>
<intbox id="arg1"/> + <intbox id="arg2"/> <button label=" = " id="addBtn" /> <label id = "ans"/>
</hbox>
</window>
public class Controler1 extends GenericForwardComposer {
private Intbox arg1; //ビューの<intbox id="arg1"/>コンポーネントと自動的に紐付けされる
private Intbox arg2; //ビューの<intbox id="arg2"/>コンポーネントと自動的に紐付けされる
private Label ans; //ビューの<label id="and"/>コンポーネントと自動的に紐付けされる
// addBtnボタンの onClickイベント・リスナー
public void onClick$addBtn(Event e) throws Exception{
ans.setValue(String.valueOf(arg1.getValue() + arg2.getValue()));
}
}

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<?variable-resolver class="org.zkoss.zkplus.seasar.DelegatingVariableResolver"?>
<window id="win" title="Employee" border="normal" width="300px" apply="MyControler">
<listbox id="empListbox" width="200px" rows="10" multiple="true" height="100%"
checkmark="true" model="@{controler.empData}" selectedItem="@{selected}">
<!--
controlerはMyControlerのdoAfterComposeメソッドでWindow変数に追加されている。
aWindow.setVariable("controler", this, true); //aWindowはdoAfterComposeの引数
empDataはcontrolerで定義されているList<Employee>型のプロパティ
-->
<listhead>
<listheader label="姓" />
<listheader label="名" />
</listhead>
<listitem self="@{each=employee}">
<listcell label="@{employee.lastName}"/>
<listcell label="@{employee.firstName}"/>
</listitem>
</listbox>
<vbox>
<hbox>姓: <label value="@{selected.lastName}"/></hbox>
<hbox>名:<label value="@{selected.firstName}"/></hbox>
<hbox>内線番号: <label value="@{selected.phoneExt}"/></hbox>
<hbox>入社日:<label value="@{selected.hireDate}"/></hbox>
</vbox>
</window>
public class MyControler extends GenericForwardComposer {
private List<Employee> empData;
private JdbcManager jdbcManager; //super.doAfterComposeのコール後Seasar変数と自動で紐付けされる
@Override
public void doAfterCompose(Component aWindow) throws Exception {
super.doAfterCompose(aWindow);
// 自分自身をwindowの変数に追加するとビューからアクセス可能なオブジェクトになる。
aWindow.setVariable("controler", this, true);
empData = jdbcManager.from(Employee.class).getResultList();
}
//zulのListboxのmodelプロパティには controler.empData を設定する
public List<Employee> getEmpData() {
return empData;
}
}
<window width="100%">
<zscript>
// コンポーネントのforEach属性を利用して生成するボタンの国名ラベルの配列
String[] countries = {"China", "France", "Germany", "United Kindom", "United States", "Japan"};
</zscript>
<hbox>
<button label="${each}" forEach="${countries}">
<!-- eachの値をcustom-attributesのcountryに保存する -->
<custom-attributes country="${each}"/>
<attribute name="onClick">
{
//countryにアクセスする。
alert(componentScope.get("country"));
}
</attribute>
</button>
</hbox>
</window>
<style>
div.cell-inner{
font-size:xx-small;
//font-size:xx-large;
}
</style>
<textbox style="text-transform:uppercase" id="idx" />
<window title="Button window" border="normal">
<vbox>
<button label="Left" width="125px">
<attribute name="onClick">
Messagebox.show("Textboxのテキストを選択状態にします");
txt.focus();
txt.setSelectionRange(0, txt.getText().length());
</attribute>
</button>
<textbox id="txt" value="123456"/>
</vbox>
</window>
<window title="Window幅のリサイズに自動で追随するリストボックス"
width="300px" height="100px" id="win" sizable="true" mode="modal">
<button label="FILL" onClick="fillList()"/>
<zscript>
public void fillList(){
Listitem item = new Listitem();
new Listcell("Cell Data 1").setParent(item);
new Listcell("Cell Data 2").setParent(item);
new Listcell("Cell Data 3").setParent(item);
item.setParent(lbx);
}
</zscript>
<listbox width="100%" id="lbx" fixedLayout="true">
<listhead sizable="true">
<listheader label="Column 1" />
<listheader label="Column 2" />
<listheader label="Column 3" />
</listhead>
</listbox>
</window>
<zk>
<desktop-config>
<desktop-timeout>3600</desktop-timeout> <!--秒単位、マイナスはタイムアウト無し。 -->
</desktop-config>
</zk>
<window title="no empty制約付きのテキストボックスをクリアする"
width="300px" height="200px" border="normal">
<zscript><![CDATA[
public void save(){
alert("テキストボックスの値 "+tb1.value+" を保存しました。");
tb1.setValue(""); //no empty制約にひっかかりクリアできない
//tb1.setRawValue(""); //制約を回避しクリアできる。
}
]]></zscript>
<vbox>
<textbox id="tb1" constraint="no empty" ></textbox>
<button label="保存" onClick="save()" />
</vbox>
</window>
<window id="win" border="normal" title="隠れません!!"
mode="overlapped" width="350px" onMove="resetTop()">
<zscript><![CDATA[
void resetTop(){
String top = win.getTop();
if (top != null){
float winTop = Float.parseFloat((top.substring(0,top.lastIndexOf("px"))));
if (winTop < 0.0){
win.setTop(0 + "px");
}
}
}
]]></zscript>
<label value="ウィンドウはスクリーントップを越えて上には移動しません!!"/>
</window>
<window width="500px" height="200px" title="親ウィンドウ
contentStyle="position:relative;"" border="normal"
contentStyle="position:relative;" >
<panel id="panel" height="100px" width="300px" title="親ウィンドウの中だけ移動するパネル"
maximizable="true" border="normal" collapsible="true" floatable="true" movable="true">
<panelchildren>
最大化しても親ウィンドウの中に収まります。
</panelchildren>
</panel>
</window>
<style>
/* 偶数行の背景色 */
tr.z-list-item, tr.z-row td.z-row-inner, tr.z-row td.z-group-inner,
tr.z-row td.z-group-foot-inner, tr.z-row {
background: #EEEEEE none repeat scroll 0 0;
}
/* 奇数行の背景色 */
tr.odd td.gc, tr.odd, tr.z-listbox-odd, tr.z-grid-odd td.z-row-inner,
tr.z-grid-odd {
background: #FFFFFF none repeat scroll 0 0;
}
/* 選択されていない行の上をマウスが通過する時の背景色 */
tr.overd, td.overd, tr.z-list-item-over {
background: #D3DBFC none repeat scroll 0 0;
}
/* 選択された行の背景色 */
tr.seld, td.seld, tr.z-list-item-seld {
background: #B8BFDC none repeat scroll 0 0;
}
/* 選択された行の上をマウスが通過する時の背景色 */
tr.overseld, td.overseld, tr.z-list-item-over-seld {
background: #D3DBFC none repeat scroll 0 0;
}
</style>
<borderlayout height="500px">
<north title="「折り畳みアイコン」を表示するには何かタイトルが必要 →"
size="20%" splittable="true" collapsible="true"/>
<east size="20%" splittable="true" collapsible="true"/>
<center border="normal"/>
<west title="→" size="20%" splittable="true" collapsible="true"/>
<south size="30%" border="normal" splittable="true" collapsible="true"/>
</borderlayout>
<window
title="Listbox with Paging Performance using ZK version: ${desktop.webApp.version}"
border="normal" use="sample.ui.EmployeeUI"
xmlns:zk="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
<zk:toolbarbutton href="/" label="Back" />
<zk:listbox id="listEmployee" width="350px" checkmark="true">
<zk:listhead sizable="true">
<zk:listheader label="ID" sort="auto" />
<zk:listheader label="Full Name" sort="auto" />
<zk:listheader label="User Name" sort="auto" />
</zk:listhead>
</zk:listbox>
<!-- 明示的にpagingコンポーネントを使用する。 -->
<zk:paging id="pageEmployee" pageSize="30" />
</window>
public class EmployeeUI extends SimpleWindow implements AfterCompose {
private final String LISTBOX_ID= "listEmployee"; //zulファイルの listbox コンポーネントの id
private final String PAGING_ID = "pageEmployee"; //zulファイルの paging コンポーネントのid
private JdbcManager jdbcManager; //Seasar変数
public EmployeeUI(){
DelegatingVariableResolver variableResolver = new DelegatingVariableResolver();
jdbcManager = (JdbcManager)variableResolver.resolveVariable("jdbcManager");
}
/**
* AfterComposeインターフェースのafterComposeメソッドはコンポーネント作成段階で処理される。
* コンポーネントを作成した直後に初期化できパフォーマンスの改善に役立つ。
*
*/
public void afterCompose() {
Paging page = getPaging(PAGING_ID);
//データのトータル行数を取得
page.setTotalSize((int)jdbcManager.from(Employee.class).getCount());
final int PAGE_SIZE = page.getPageSize();
// Listboxに最初のページを表示 オフセット--0 行数---PAGE_SIZE
redraw(0, PAGE_SIZE);
// onPagingイベントリスナの登録 決まり文句
page.addEventListener("onPaging", new EventListener() {
public void onEvent(Event event) {
PagingEvent pageEvent = (PagingEvent) event;
int pageNo = pageEvent.getActivePage();
int offset = pageNo * PAGE_SIZE;
// クリックされたページ番号でライブデータを取得し再表示
redraw(offset, PAGE_SIZE);
}
});
}
/**
* afterCompose及びonPagingイベントリスナから呼び出されListboxを描画する。
* コールされる度にクエリを実行しデータベースからライブデータを取得する。
*
* @param firstResult オフセット
* @param maxResults 行数
*/
private void redraw(int firstResult, int maxResults) {
Listbox listBox = getListbox(LISTBOX_ID);
listBox.getItems().clear();
// データ取得
List<Employee> emps = jdbcManager.from(Employee.class)
.orderBy("id") // 問い合わせ結果をページングするにはorder by が必要
.offset(firstResult)
.limit(maxResults)
.getResultList();
// 表示
for (Employee employee : emps) {
Listitem li = new Listitem();
li.setValue(employee);
li.appendChild(new Listcell("" + employee.id));
li.appendChild(new Listcell(employee.fullname));
li.appendChild(new Listcell(employee.username));
listBox.appendChild(li);
}
}
}
create table FinancialData (
fyear integer,
fquarter integer,
item char(10),
liquidAssets decimal(10, 0),
fundInvestment decimal(10, 0),
fixedAssets decimal(10, 0),
intangibleAsset decimal(10, 0),
otherAssets decimal(10, 0),
currentLiabilities decimal(10, 0),
longTermLiabilities decimal(10, 0),
otherLiabilities decimal(10, 0),
capitalStock decimal(10, 0),
capitalSurplus decimal(10, 0),
retainedEarnings decimal(10, 0),
otherEquity decimal(10, 0),
treasuryStock decimal(10, 0)
);
insert into FinancialData(
fyear,
fquarter,
item,
liquidAssets,
fundInvestment,
fixedAssets,
intangibleAsset,
otherAssets,
currentLiabilities,
longTermLiabilities,
otherLiabilities,
capitalStock,
capitalSurplus,
retainedEarnings,
otherEquity,
treasuryStock
)values(
2007,
1,
'Quarter',
146504221,
23181709,
7168392,
221426,
2270018,
102515784,
3000,
456175,
33630080,
7127901,
34420905,
1826731,
-634810
);
...
package churazk.entity;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name="FINANCIALDATA")
public class FinancialData {
@Column(name="fYear")
public Integer fYear;
@Column(name="fQuarter")
public Integer fQuarter;
@Column(name="item")
public String item;
@Column(name="liquidAssets")
public BigDecimal liquidAssets;
@Column(name="fundInvestment")
public BigDecimal fundInvestment;
@Column(name="fixedAssets")
public BigDecimal fixedAssets;
@Column(name="intangibleAsset")
public BigDecimal intangibleAsset;
@Column(name="otherAssets")
public BigDecimal otherAssets;
@Column(name="currentLiabilities")
public BigDecimal currentLiabilities;
@Column(name="longTermLiabilities")
public BigDecimal longTermLiabilities;
@Column(name="otherLiabilities")
public BigDecimal otherLiabilities;
@Column(name="capitalStock")
public BigDecimal capitalStock;
@Column(name="capitalSurplus")
public BigDecimal capitalSurplus;
@Column(name="retainedEarnings")
public BigDecimal retainedEarnings;
@Column(name="otherEquity")
public BigDecimal otherEquity;
@Column(name="treasuryStock")
public BigDecimal treasuryStock;
}
<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.seasar.DelegatingVariableResolver"?>
<window>
Quarter:
<listbox id="quarter" mold="select" rows="1" onSelect="refreshQuarter()">
<listitem value="0" label="Select"/>
<listitem value="1" label="Quarter 1"/>
<listitem value="2" label="Quarter 2"/>
<listitem value="3" label="Quarter 3"/>
<listitem value="4" label="Quarter 4"/>
</listbox>
Style:
<listbox id="style" mold="select" rows="1" onSelect="changeStyle()">
<listitem label="Style 1" value="/BalanceSheet.xls"/>
<listitem label="Style 2" value="/NewSheet.xls"/>
</listbox>
<zscript>
import churazk.entity.FinancialData;
import org.seasar.extension.jdbc.where.SimpleWhere;
FinancialData reloadQuarter(int quarter){
FinancialData bean = jdbcManager.from(FinancialData.class)
.where(new SimpleWhere()
.eq("fYear", 2007)
.eq("fQuarter", quarter)
)
.getSingleResult();
return bean;
}
void refreshQuarter() {
Listitem listitem = quarter.getSelectedItem();
int quarter = Integer.parseInt(listitem.value);
//Call the method to reload data
dataBean = reloadQuarter(quarter);
//Call the method to refresh values of cells
balance.book.notifyChange(new String[]{"dataBean"});
}
void changeStyle() { //Change the URL of spreadsheet
balance.url = style.getSelectedItem().value;
}
dataBean = reloadQuarter(0);
</zscript>
<spreadsheet id="balance" url="/BalanceSheet.xls" maxrow="40" maxcolumn="20" height="600px" width="1300px"/>
</window>
commons-math-1.2.jar
jxl.jar
zss.jar
zssex.jar
zssjxl.jar

OS: Ubuntu 8.04 JDK: 1.6.0_04 Tomcat: apache-tomcat-6.0.16 Eclipse: Europa wtp-all-in-one-sdk ZK: zk-3.0.5 Seasar: DoltengプラグインよりChuraプロジェクト(Teeda+S2Dao)として S2JDBC関連: sa-struts-tutorial-1.0.2-rc4.zipより
geronimo-jpa_3.0_spec-1.0.jar
geronimo-ejb_3.0_spec-1.0.jar
s2jdbc.diconweb.xml追加
<!-- ZK -->
<listener>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup><!-- Must -->
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<!-- Miscellaneous -->
<session-config>
<session-timeout>120</session-timeout>
</session-config>
<!-- ZK -->