-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
is this s bug or expected behaviour? The code bellow selects the first item in the listbox instead of the fourth one:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <window id="win"> <zscript><![CDATA[ List list1 = new ArrayList(); list1.add("A"); list1.add("B"); list1.add("C"); list1.add(null); ]]></zscript> List1 <listbox id="listbox1" mold="select" rows="1" model="@{list1}" selectedItem="@{selected1}"> <listitem self="@{each=listEach}" label="@{listEach}" /> </listbox> ]]></zscript> </window>
Hi,
I think the default typeconverter (for selectItem) will ignore null-converts.
Could help:
1.) Make a copy of the SelectListitemConverter and customize the typeconverter to handle null values.
2.) wrapp this into an object: object.name = "None", object.value = null (instead of string)
3.) Use "" instead of String (of course need something like if (value.equals("")) // null-branch
This works:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./win"?>
<window id="win">
<zscript>
List list1 = new ArrayList();
list1.add("A");
list1.add("B");
list1.add("C");
list1.add("");
String selected1 = "";
</zscript>
List1
<listbox id="listbox1" mold="select" rows="1" model="@{list1}" selectedItem="@{selected1}">
<listitem self="@{each=listEach}" label="@{listEach}" />
</listbox>
<label value="@{selected1}"/>
</window>
However, if have always (wrapper)beans (Variant B) and no pure Strings's in my applications.
/Robert
Hi Robert,
I have used String in my example to simplify it, but I use a bean in my application. It's a typical JPA @ManyToOne(optional=true) relationship, where the "many" side has a limited (5-20) number of entities. I have finally made a databinding "access=save" only and I programmatically call setSelectedIndex(...). Thank you for your post, I will try to customize your SelectListitemConverter.
BTW. I think is should be a job of ListModel to handle the null values, the default SelectListitemConverter should just pass the null values to the ListModel.
Please post it to feature request.
Asked: 2010-04-23 04:42:46 +0800
Seen: 283 times
Last updated: Apr 26 '10