-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a window containing multiple grids with the rows bound using the standard pattern:
<grid model="@{myModel}"> <rows> <row self="@{each=entry}"> <label value="@{entry.name}" /> <textbox value="@{entry.value}"/> </row> </rows> </grid>
Is this a bug or just my misunderstanding of ID spaces?
(It doesn't seem useful to have the binding variable scoped outside of the component's ID space, so it seems like a bug.)
Hi,
Please try revising a line of your code
<row self="@{each='entry'}">
Does that help?
That doesn't seem to help. In the following test page, try editing one of the cells in the two grids and then click outside the cell. You should see the "Cannot find associated CollectionItem" error. If you change the two mybean variables names to mybean1 and mybean2, the error should go away.
<?page title="Data Binding Variable Scoping" contentType="text/html;charset=UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <window id="win"> <vbox> <zscript><![CDATA[//@DECLARATION final class Bean{ public String name; public Bean(String name){this.name = name;} } ]]> <![CDATA[// // make the list models ArrayList list1 = new ArrayList(); for( Bean s : new Bean[]{new Bean("a"),new Bean("b"),new Bean("c")} ) list1.add(s); ArrayList list2 = new ArrayList(); for( Bean s : new Bean[]{new Bean("x"),new Bean("y"),new Bean("z")} ) list2.add(s); ]]> </zscript> <grid id="grid1" model="@{list1}"> <rows> <row self="@{each='mybean'}"> <textbox value="@{mybean.name}" /> </row> </rows> </grid> <grid id="grid2" model="@{list2}"> <rows> <row self="@{each='mybean'}"> <textbox value="@{mybean.name}" /> </row> </rows> </grid> </vbox> </window> </zk>
Hi,
Thanks for sample code, I've tried it and got the same error, but I have no idea about this, maybe that's spec of ZK or really a bug.
Anyway, I revised the code with another way, please give it a try
<?page title="Data Binding Variable Scoping" contentType="text/html;charset=UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript><![CDATA[//@DECLARATION final class Bean{ public String name; public Bean(String name){this.name = name;} public String getName(){ return name; } } ]]> <![CDATA[// // make the list models ArrayList list1 = new ArrayList(); for( Bean s : new Bean[]{new Bean("a"),new Bean("b"),new Bean("c")} ) list1.add(s); ArrayList list2 = new ArrayList(); for( Bean s : new Bean[]{new Bean("x"),new Bean("y"),new Bean("z")} ) list2.add(s); ]]> </zscript> <window id="win"> <vbox> <grid id="grid1" > <rows> <row forEach="${list1}" > <textbox value="${each.name}" /> </row> </rows> </grid> <grid id="grid2" > <rows> <row forEach="${list2}" > <textbox value="${each.name}" /> </row> </rows> </grid> </vbox> </window> </zk>
>> sreed
Updating the models causes the "Cannot find associated CollectionItem" error. Changing the binding variable name, "entry", to something unique for each grid fixed the problem. I was expecting the binding variable name to be in the ID space of the grid component but evidently this is not so.
<<
I can confirm this problem. It costs me one hour to find...
<row self="@{each='mybean'}">
First, (i think) mybean is not a part of the idspace. It's only a workingname for then databinder. And it seems that it has to be unique for the databinderinstance.
/Robert
Hideokidd,
As I understand it, your approach fixes the problem by avoiding the binder altogether. I prefer using unique binder variable names since it still allows use the binder, but it's helpful to know your option is available.
>>Robert
<row self="@{each='mybean'}">
First, (i think) mybean is not a part of the idspace. It's only a workingname for then databinder. And it seems that it has to be unique for the databinderinstance.
<<
I would be surprised to learn that the same binder instance is used for every binding. I think we've taken this as far as we can now and need a developer to take over at this point. It does appear to be a bug.
Thanks for your help,
Scott
Asked: 2009-03-26 20:44:21 +0800
Seen: 608 times
Last updated: Mar 29 '09