sort of frustrating ...radio value really needs to handle more than String datatype [closed]

asked 2014-09-22 20:46:13 +0800

rickcr gravatar image rickcr
704 7

(Using zk 7.0.3) I posted way back related to a radio button only binding to a String value when I wanted it to set an int. Now I'm in a similar position trying to bind 'true' 'false' to a boolean property on a form's backing object.

I'm not sure why this isn't a priority for the ZK team since going way back to Struts 1.x we had the ability to bind values of different data types. I haven't looked at the source code but surely by reflection you could know the target property's data type and convert accordingly?

My cheezy solution which is frustrating is to make an ugly string property on my ViewModel which in turn has to set the underlying form baking object's boolean property.

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by rickcr
close date 2014-09-24 01:48:29

4 Answers

Sort by ยป oldest newest most voted

answered 2014-09-23 22:44:30 +0800

cor3000 gravatar image cor3000
5364 2 7
ZK Team

updated 2014-09-23 22:47:27 +0800

I stick to my initial answer (it uses Locale as value class, not String!), the most flexible way is to use a ListModel with the available choices and then use a template to render render custom or localized labels.

ZK handles the conversion as you can see in your updated example, all I do is specialize the labels in various ways just to give you an idea of the many possible ways.

I use a map of "mylabels" to simulate the ZK predifined variable "labels" which is used for localization (there is just no way to add new label properties in fiddle)

link publish delete flag offensive edit


Cool stuff Robert! Thanks a lot. That does seem like the best approach to creating the radio buttons. I'll work on it that way. Your updated example was EXTREMELY helpful. Much appreciated.

rickcr ( 2014-09-24 01:47:21 +0800 )edit

answered 2014-09-23 01:57:11 +0800

cor3000 gravatar image cor3000
5364 2 7
ZK Team

updated 2014-09-23 01:57:52 +0800

Hi rickcr,

from your descriptions I cannot comment on what you are trying. So here an example for a radiogroup that uses non-string Objects as the value for each radio (java.util.Locale) in the radiogroup.

Radio extends Checkbox, and inherits separate properties for label, value and name. So you can assign each separately.

And using ListModel<your_type> (with a template) makes this especially easy. Maybe you can post an example on fiddle that does not work, and I can check if it is a bug or missing feature.


link publish delete flag offensive edit


in MVVM you can get the selected Object(s) from the ListModelList directly (model.getSelection())

cor3000 ( 2014-09-23 03:46:37 +0800 )edit

answered 2014-09-23 13:19:02 +0800

rickcr gravatar image rickcr
704 7

Hi Robert thanks for replying. In your example you were using Strings. Investigating a bit more I realized the underlying value object property IS being set correctly when the radio button is a number or boolean, however, for some reason, the radio button itself won't stay selected.

I think this example will illustrate. Note the "hack" that does work.

In this example http://zkfiddle.org/sample/2q9p5js/3-Radiogroup-With-Non-Strings if you click different buttons you'll see the values change correctly below, but the radio button checked option for the selected item is not working as I'd expect.

link publish delete flag offensive edit

answered 2014-09-23 14:24:47 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9

updated 2014-09-23 14:25:01 +0800

Hi Rickcr,

You make one small fault.
When you do the each="7" or each="true" you set String as object.

See your updated fiddle.

Greetz chill.

link publish delete flag offensive edit


That approach is cumbersome as well. Say I'm creating a form with many booleans.. I have to now make VM getters/setters for EVERY boolean? You'd think ZK could just attempt to cast to the resulting property on the backing vo...or if it helps, allow an extra field on radio to let me declare the type

rickcr ( 2014-09-23 14:47:03 +0800 )edit

@converter could do the trick. : http://books.zkoss.org/wiki/ZKDeveloper'sReference/MVVM/Data_Binding/Converter

chillworld ( 2014-09-23 15:02:14 +0800 )edit

Agreed a converter could do it, however, considering most other web-based frameworks handle this type of conversion automatically, I'm surprised ZK does not by default. If there is not a ticket in for this enhancement already, I'll add one. Thanks.

rickcr ( 2014-09-23 16:44:43 +0800 )edit

You could create your own component, I have a custom component what works for all abstractCatalog implementations, just need to add class="SomeCatalog" (needed it for when he receive null as initial object=> unable to detect what class they wanted)

chillworld ( 2014-09-23 16:55:09 +0800 )edit

Question tools

1 follower



Asked: 2014-09-22 20:46:13 +0800

Seen: 29 times

Last updated: Sep 23 '14

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