0

Scoping of databinding vars - Cannot find associated CollectionItem

asked 2009-03-26 20:44:21 +0800

sreed gravatar image sreed
195 1 3 5

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>

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.

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.)

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-03-27 01:38:14 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-03-27 01:38:47 +0800

Hi,

Please try revising a line of your code

<row self="@{each='entry'}">

Does that help?

link publish delete flag offensive edit

answered 2009-03-28 13:17:24 +0800

sreed gravatar image sreed
195 1 3 5

updated 2009-03-28 14:39:04 +0800

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>

link publish delete flag offensive edit

answered 2009-03-28 16:36:38 +0800

hideokidd gravatar image hideokidd
750 1 2

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>

link publish delete flag offensive edit

answered 2009-03-28 21:52:23 +0800

robertpic71 gravatar image robertpic71
1275 1

>> 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

link publish delete flag offensive edit

answered 2009-03-29 15:50:34 +0800

sreed gravatar image sreed
195 1 3 5

updated 2009-03-29 15:52:19 +0800

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

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-03-26 20:44:21 +0800

Seen: 608 times

Last updated: Mar 29 '09

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