# I cannot get databinding to work with listbox.

orthello
18 2

<groupbox>
<listbox id="usersLB" multiple="true" rows="14" model="@{hboxx$composer.users}"> <listhead> <listheader label="Users"/> </listhead> <listitem self="@{each='user'}" value="@{user}"> <listcell label="@{user.fullname}"/> </listitem> </listbox> </groupbox> ... public class UserAdminGFC extends DbSessionGFC { private List<User> cAllUsersL; ... public List<User> getUsers () throws SQLException, SqlExecutorException { Connection _C = getDbConnection (); try { SelectUserListSql _SULS = new SelectUserListSql ( _C ); cAllUsersL = _SULS.getSelectResult (); } finally { _C.close (); } return cAllUsersL; } ... } public class User { ... private String cFullName; public User () { } ... public void setFullName ( String fullName ) { cFullName = fullName; } public String getFullName () { return cFullName; } ... } The method getUsers is never called. Shouldn't the following line make getUsers get called? <listbox id="usersLB" multiple="true" rows="14" model="@{hboxx$composer.users}">

One wierd thing is that all my onClick@xxx methods within UserAdminGFC are called
correctly. What am I missing?

James Wilson
jwilson@nmcourt.fed.us
(505) 228-5233

delete retag edit

## 7 Replies

caclark
1753 2 5
http://clarktrips.intltwi...

1) You see the # button above the forum text editor alongside the B, I, & U? It's for code. It sure makes reading your code much easier.
2) You didn't show all of your ZUL file. Did you put the AnnotateDataBinderInit in it?

orthello
18 2

I did put AnnotateDataBinderInit in it.

I think the problem has to do with the fact that I create
tabbedpanels dynamically and then make a include call to include
the zul for each tabbedpanel. When I put AnnotateDataBinderInit
in my include call I get an error because AnnotateDataBinderInit

<zk>
<?init class="us.fed.nmcourt.jaa.db.CreateDatabasePoolInitiator"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<window
id="mainWindow"
title="Judge Assignment Application"
border="normal"
position="center"
mode="modal"
closable="true"
apply="us.fed.nmcourt.jaa.win.MainWindowGFC">
<tabbox id="mainTabBox">
<tabs id="mainTabs">
</tabs>
<tabpanels id="mainTabPanels">
</tabpanel>
</tabpanels>
</tabbox>
</window>
</zk>

caclark
1753 2 5
http://clarktrips.intltwi...

I haven't added tabs dynamically, but others on the forum have. I think you're going to need to have a reference to the binder in your GFC subclass and add the tabpanel as a component so that the binder knows about it. When the binder initiates, your tab panel isn't there, so it doesn't do any binding.

private AnnotateDataBinder binder = null ;

to your controller and see if any of the AnnotateDataBinder::addBinding(...) methods can be used.

orthello
18 2

Ok, if I wait to include AnnotateDataBinderInit until after all my dynamic tabpanels are loaded then databinding works.
What is the best way to invoke AnnotateDataBinderInit programatically?

orthello
18 2

I'll look into you suggestion right away.

James

caclark
1753 2 5
http://clarktrips.intltwi...

...and if all else fails you can create your own binder...

binder = new AnnotateDataBinder(comp, b);

You might peek @ the source for AnnotateDataBinderInit::doAfterCompose(Page page, Component[] comps) to see if you can get any clues from it.

orthello
18 2

It's working!

I put the AnnotateDataBinderInit zul call in one of the dynamic tabpanels that all the users will get.

[hide preview]