-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am trying to do automated data-binding with a datastructure consisting of List of List, and having trouble to get it to work.
Below is a self-contained sample test code. It displays fine, but nothing got bound after data entry. The strangest thing is that the data entered in the first row is always automatically deleted. Any help is really appreciated. Thanks.
-JJ
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript> import java.util.*; List entries = new LinkedList(); for (int i = 0; i < 4; i++) { List x = new LinkedList(); for (int j =0; j < 2; j++) { x.add(new String("")); } entries.add(x); } public void printData() { System.out.println("bound value 1=" + entries.get(0).get(0)); } </zscript> <panel title="test" > <panelchildren style="padding:5px;" > <grid> <columns> <column label="col1" /> </columns> <rows> <row forEach="${entries }" > <variables bar="${each }" /> <div> <label value="${forEachStatus.index + 1}" /> <grid model="@{bar}" > <rows> <row self="@{each='entry' }" > <textbox value="@{entry}" /> </row> </rows> </grid> </div> </row> </rows> </grid> </panelchildren> <toolbar mold="panel" align="center"> <button label="OK" width="65px" onClick="printData()" /> </toolbar> </panel> </zk>
Hi,jj
databinding is call setXXX to update a new value
JVM cannot to set a new String object instead of old one auto
you most be use a bean and has setter getter
like this
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript><![CDATA[ import java.util.*; class Abc{ String a; public void setA(String aa){a = aa;} public String getA(){return a;} } List entries = new LinkedList(); for (int i = 0; i < 4; i++) { List x = new LinkedList(); for (int j = 0; j < 2; j++) { Abc abc = new Abc(); abc.setA(i+""+j); x.add(abc); } entries.add(x); } public void printData() { System.out.println("bound value 1=" + entries.get(0).get(0).a); } ]]> </zscript> <panel title="test"> <panelchildren style="padding:5px;"> <grid model="@{entries}"> <columns> <column label="col1" /> </columns> <rows> <row self="@{each='bar'}"> <div> <grid model="@{bar}"> <rows> <row self="@{each='x'}"> <textbox value="@{x.a}"/> </row> </rows> </grid> </div> </row> </rows> </grid> </panelchildren> <toolbar mold="panel" align="center"> <button label="OK" width="65px" onClick="printData()" /> </toolbar> </panel> </zk>
Asked: 2009-11-02 14:08:40 +0800
Seen: 529 times
Last updated: Nov 03 '09