asked
2015-09-06 01:31:30 +0800
yagamipaul 15 ● 2 Hi,
I'm testing ZK8, but found a little bug in form binding. I'm using a POJO to store my form properties, one of the form elements is an object with 2 properties (label,value), and I'm binding it to the selectedItem property of a listbox with mold=select.
I'm using the @init
to initialize some values of the form (show the values when the form is rendered), it works properly with any value in my POJO (string, int, double, ...), but no with my Object:
public class ListValueDTO<T> implements Serializable {
private String label;
private T value;
....
}
// vm.form Object
public class ChangeClientAccountRequest implements Serializable {
private Long clientId;
private ListValueDTO<String> country;
....
}
<u:div xmlns="native" xmlns:u="zul" xmlns:zk="zk" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.Controller')" validationMessages="@id('vmsgs')"
form="@id('fx') @load(vm.form) @save(vm.form, before='commandSave') @validator(vm.validator)">
..
the model list vm.countries is a
List<ListValueDTO<String>>
my listbox definition:
<u:listbox mold="select" model="@load(vm.countries)" selectedItem="@bind(fx.country)">
<zk:template name="model">
<u:listitem label="@load(each.label)" value="@load(each.value)" />
</zk:template>
</u:listbox>
My controller init's method:
@Init
public void init() {
final Long clientId = ZKCustomUtils.getCurrentClientId();
this.client = this.facade.findClientById(clientId);
// Form set-up
form.setCountry(new ListValueDTO<String>("Colombia","CO");
this.countries = this.facade.getCountries();
form.setClientId(clientId);
form.setClientName(client.getName());
....
}
This used to work in ZK 7.0.3 CE, now in ZK 8.0.0-RC is not working.
With some debugging, found that org.zkoss.bind.proxy.ProxyHelper.createProxyIfAny(T, Annotation[]):91
is creating a Proxy of my object with null values inside, but with a property of type String, double is returning the same object (as it checks for immutable).
I'm not sure if thats the reason why my Listbox is not getting the default value in my form.
Not sure if I mark my property getter with @Immutable could work, but I cannot, my POJOS are inside a ZK Free jar.
Thanks in advance.
Jean Paul Manjarres C.
you could try latest version 8.0.0.FL.20150904-Eval or get it from http://www.zkoss.org/download/freshly/
hawk ( 2015-09-07 01:49:18 +0800 )editHi, I did try too with that version, but the same happens. I use maven for dependency management.
yagamipaul ( 2015-09-07 16:43:02 +0800 )edit