0

Databinding with nested list problem

asked 2009-11-02 14:08:40 +0800

jj gravatar image jj
638 3

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>

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2009-11-03 20:05:47 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2009-11-03 20:06:51 +0800

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>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-02 14:08:40 +0800

Seen: 529 times

Last updated: Nov 03 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More