Revision history [back]

click to hide/show revision 1
initial version

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

rickcr gravatar image rickcr

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 drop down are often slightly different than the one you want to bind to.. so you can't have the equals method always work. Plus, often we work on large teams and you can't start altering the equals method on other's domain objects.

The solution be 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 would be

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

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 drop down listboxes are often slightly different than the one you want to bind to.. hydration of the object you are testing for equality with - so you can't have the equals method always work. Plus, 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 we work on large teams and you can't start altering the equals method on other's domain objects.objects you often don't control.

The solution be 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 would becould 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.)

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