-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everybody,
I'm having a problem setting a databiding for an ArrayList in a listbox.
<!-- person.getPhones() returns a List<Phone>, the variable person is in page scope --> <listbox id="phones" width="200px" rows="4" model="${person.phones}"> <listhead> <listheader label="type" /> <listheader label="number" /> </listhead> <listitem self="@{each='phone'}"> <listcell> <label value="@{phone.type}" /> </listcell> <listcell> <label value="@{phone.phoneNumber}" /> </listcell> </listitem> </listbox>
Person.java
public class Person{ private List<Phone> phones; ... }
Phone.java
public class Phone{ private String type; private String phoneNumber;
As I can access other person attributes (like person.name) in the page, I'm trying to set the model for the listbox as person.phones. Is it right?
Is there something wrong in this code?
instead use model, try use
<listbox id="phones" width="200px" rows="4" forEach="${person.phones}">
I don't see how it works. Using forEach, the listbox would be rendered N number of times. Using databinding, the evaluation is done much later. Using the forEach method would require you to populate the phones in the person instance quite early.
I would have expected this to cure your problem:
<listbox id="phones" width="200px" rows="4" model="@{person.phones}">
I think you should use a debugging tool and see how the phone UI element(s) are really being rendered.
Claclark, the code in the first post is wrong, it was returning error 500, and I didn't fix it before copying it.
The code you posted is what I was using before, but it didn't work too. I saw the code in this tutorial: http://docs.zkoss.org/wiki/Data_binding
I also tried @<{person.phones>}, but it was a shot in the dark, and still didn't work.
Hey marcio0,
Just checking, in your bean do you have the function:
public List<Phone> getPhones() { return this.phones; }
Tmillsclare, yes, it does.
I'm following this tutorial: http://docs.zkoss.org/wiki/Data_binding#Associate_UI_Components_with_a_Collection
I found more information about the forEach method in this one: http://docs.zkoss.org/wiki/Data_Binding_Collection_Data_with_ZUML_Annotations
But it seems to be older than the first.
Hey Marcio,
I think I may know what is going wrong. Are you using zscript? If not are you using the apply="MyComposer" attribute on either the listbox or one of its parents and extending GenericForwardComposer? The latter refer to using ZK in an MVC compliant manner, if not then that is your problem. For more information on using ZK in an MVC manner please take a look at http://docs.zkoss.org/wiki/MVC_in_ZK.
Please let me know if that helps!
So, marcio0, do you have it working?
Asked: 2010-02-09 08:24:50 +0800
Seen: 320 times
Last updated: Feb 22 '10