ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

ListBox selectedItems

dickdastardly
15 Mar 2010 13:14:17 GMT
15 Mar 2010 13:14:17 GMT

Shouldnt i be able to select multiple items from a listbox using something like this?

<listbox model="@{referenceData.allergies}" checkmark="true"
	multiple="true" selectedItems="@{children.allergyType}">
	<listitem self="@{each='childAllergy'}" value="@{childAllergy}">
		<listcell label="@{childAllergy.description}" />
	</listitem>
</listbox>

and NOT have to write any java code to get the selected items back set in a Set?

my session attribute children.allergyType is a java Set
shouldnt this be getting populated from the selected items from the listbox?

dickdastardly
16 Mar 2010 00:03:07 GMT
16 Mar 2010 00:03:07 GMT

why is'nt this easy?

why does zk have a listbox component that has multiple attribute you simply have to set to true to allow
multiple selections from the displayed this...

However it appears to be so hard to retrieve those selected items back into your data model!

why is'nt there a demo/docs showing how to do this?

do you really have to write java controller to be able to do this for every multiple selection listbox
within an app?

iantsai
17 Mar 2010 02:50:10 GMT
17 Mar 2010 02:50:10 GMT

I'm not sure the question you have, so maybe I should verify it at first.

you have a variable named "children" which is an attribute stored in session, this "children" has a property named "allergyType"( with setter& getter methods).

now you want to bind this "children"'s "allergyType" to listbox's selectedItems, which means every time App User changed his selection of this listbox, the setAllergyType(Set<Listitem>) will be triggered.

is that true?

dickdastardly
17 Mar 2010 13:18:46 GMT
17 Mar 2010 13:18:46 GMT

That is an accurate description of my problem

allergyType is a java Set<AllergyType> and I would like each and every selected allergy type to be populated in this set

I've read that zk listboxes do not support multiple selections and you have to write some java code for type converters and extend listbox itslf to make this work

Cheers

DD

iantsai
17 Mar 2010 22:07:43 GMT
17 Mar 2010 22:07:43 GMT

I think implement a converter is what you need to implement as least, I know this part could be a good feature that ZK should implement, maybe you can shoot a feature request.
(I think this is also a good Sample Code to be putted into ZK Studio's sample code)

dickdastardly
18 Mar 2010 00:03:37 GMT
18 Mar 2010 00:03:37 GMT

Do you know of a good example of how to develop a Converter?

Especially if there is one for ListBox

terrytornadoTop Contributor
18 Mar 2010 02:55:55 GMT
18 Mar 2010 02:55:55 GMT

Samples for converters can be found at RoberPic's sample page here .

best
Stephan

robertpic71Top Contributor
18 Mar 2010 11:16:12 GMT
18 Mar 2010 11:16:12 GMT

Check also this thread for the "ListitemsConverterV3".
And follow the whole thread for the "community-patches".

This Typeconverter manage n:m relations.

/Robert

xnguyen
18 Mar 2010 22:56:56 GMT
18 Mar 2010 22:56:56 GMT

I can testify that the robertpic71's ListitemsConverterV3 worked for me. I just wish it was included in the next ZK release.

dickdastardly
19 Mar 2010 03:21:13 GMT
19 Mar 2010 03:21:13 GMT

Thanks to everyone that has replied on this thread
and finally after a week of trying selectedItems i get my listbox multiple selections working

As I am using zk 5 ee i would have expected this to be working now.

Not wanting to sound ungrateful or anything, zk has such a brilliant look and feel, but this "feature"
of not being able to get multiple selections is a real depressing problem.

I am trying to keep my application as light as possible and having to write my own java code (or actually cut and paste from
robertpic71 :-)) to get the desired result is hurting me.

Thanks again to everyone

DD

iantsai
21 Mar 2010 23:25:59 GMT
21 Mar 2010 23:25:59 GMT

I'll send this feature request to ZK Team, I think it's a general requirement.

dickdastardly
22 Mar 2010 00:22:03 GMT
22 Mar 2010 00:22:03 GMT

Dear iantsai

thanks for looking at this

I look forward to seeing selecteditems start to work

Cheers

DD