ZK8 Listbox not loading data when using form binding and object property

asked 2015-09-06 01:31:30 +0800

yagamipaul gravatar image yagamipaul
15 2


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


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)" />

My controller init's method:

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();        

.... }

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.

delete flag offensive retag edit


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

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

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-18 02:24:56 +0800

rickcr gravatar image rickcr
704 7

updated 2015-09-18 02:29:53 +0800

I posted a lot about this as well here http://tracker.zkoss.org/browse/ZK-2853

I still "strongly" believe that the ZK team should consider making cor3000's converter there as BUILT INTO ZK.

I can't tell you how frustrating it is that, not just for the proxy issue above, but more importantly that you have to have an equals method defined! The reason this is bad is your hydrated objects for your listboxes are often slightly different than the hydration of the object you are testing for equality with - so you can't have the equals method always work, unless you alter the equals method to something generic like comparing only "id." But this is obviously bad for when you want to have your equals method determine object equality on something more complete, and also developers often work on large teams and you can't start altering the equals method on domain objects you often don't control.

The solution to me is so simple, as I point out. Simply provide an "selectedItemEqualsProperty" attribute on things like listboxes which could then use a built in convertor like cor3000 provided. This way you could bind on ANY equals property that you want. For example in your case it could turn to:

<u:listbox mold="select" model="@load(vm.countries)" selectedItem="@bind(fx.country)" selectedItemEqualsProperty="code">

assuming you wanted to match on country code.

Note in your case yagamipaul I got around that issue by just binding to the vm's object instead of the form proxy...

<u:listbox mold="select" model="@load(vm.countries)" selectedItem="@bind(vm.yourFormObject.country)"  >

That's what I did. But I still hate that ZK relies on that equals method implementation and doesn't provide a built in override to provide your choice of what you want to define equals on. (Sheesh, even Struts from 15 years ago had the ability to do just that - provide the property you wanted to test for marking something selected.)

link publish delete flag offensive edit


Hi, I found very useful your response. We have the same problem, but sadly I cannot use the workaround to bypass the formproxy object, I was using that feature for a custom form validation procedure that would break if I bypass any property, don't know if the converter would be too much...

yagamipaul ( 2015-10-12 18:30:56 +0800 )edit

That convertor posted here http://tracker.zkoss.org/browse/ZK-2853 should work just fine for you. Granted, as I pointed out, I think this should be built in to the listbox. I do hope the ZK team reconsiders not providing a built in convertor for such a common issue.

rickcr ( 2015-10-12 19:01:03 +0800 )edit

Thanks!, I totally agree, ZK team should provide this in the core. End users could make big errors while trying to code something like this. Sadly, the newly released 8.0.0 still have the same problem.

yagamipaul ( 2015-10-14 18:49:24 +0800 )edit
Your answer
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

1 follower



Asked: 2015-09-06 01:31:30 +0800

Seen: 64 times

Last updated: Sep 18 '15

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