0

DataBinder cannot select a null value?

asked 2010-04-23 04:42:46 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

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>

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2010-04-23 08:57:50 +0800

robertpic71 gravatar image robertpic71
1275 1

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

link publish delete flag offensive edit

answered 2010-04-26 01:45:36 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

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.

link publish delete flag offensive edit

answered 2010-04-26 02:03:21 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

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.

link publish delete flag offensive edit

answered 2010-04-26 04:30:32 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Please post it to feature request.

link publish delete flag offensive edit
link publish delete flag offensive edit
Your reply
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

Follow

RSS

Stats

Asked: 2010-04-23 04:42:46 +0800

Seen: 283 times

Last updated: Apr 26 '10

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