-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I can bind data to textbox - easy:
<textbox height="100px" width="100%" multiline="true" value="@{controller.textboxdata}" />
but how do I bind data to a radiogroup???
<radiogroup id="mything">
<radio label="123"/>
<radio label="456"/>
<radio label="789"/>
<radio label="000"/>
</radiogroup>
there seems to be no value or model or anything...
any ideas?
help apreciated.
kind regards
Florian
Hello !
yes, there is no model and I miss radioGroup.setModel( model ) similar to listboxes too.
I use (with java) radiogroup.setSelectedIndex( radioNumberToSet );
or if you assign each radio an id: radioToSet.setChecked( true|false );
so .....
/Horst
right does not work with databinding.
I just use "getSelectedItem().getLabel()"
(dont use getValue - doesnt return anything!)
It would be nice to know which Components support @databinding and which don´t!
anyway - have a nice day
I cannot catch your problem. You don't need do any javacode for binding, just
<radiogroup id="rating" selectedItem="@{controller.PersonBean.rating}"> <radio value="1" label="Actually, I hate me."/> <radio value="2" label="Not so much."/> <radio value="3" label="I'm indifferent."/> <radio value="4" label="I'm pretty neat."/> <radio value="5" label="I'm totally in love with me."/> </radiogroup>
The value rating from PersonBean is set to "1", "2", "3", "4", "5".
However, there are some limits:
- since there is no model, you could annotate the radio-items
- Radio.value could only hold String - no Object
- for static radiogroups (content known at rendertime) you could use forEach="${List}"
Of course, i would prefer an @bindingmodel and/or @forEach, but it is possible to bind radiogroup
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./mywin"?> <window id="mywin" title="Hibernate" border="normal"> <zscript> //init example data beans import org.zkoss.zkdemo.userguide.Person; List persons = new ArrayList(); persons.add(new Person("Balu", "Haben")); persons.add(new Person("Sadira", "Jobs")); persons.add(new Person("Dacey", "Obert")); persons.add(new Person("Gabby", "Taffy")); Person selected = persons.get(0); </zscript> <listbox model="@{persons}" selectedItem="@{selected}" rows="5"> <listitem self="@{each=person}" label="@{person.fullName}" /> </listbox> <grid> <columns> <column label="First Name" /> <column label="Last Name" /> <column label="Full Name" /> </columns> <rows> <row> <radiogroup selectedItem="@{selected.firstName}"> <radio forEach="${persons}" value="${each.firstName}" label="${each.firstName}"/> </radiogroup> <textbox value="@{selected.lastName}" /> <label value="@{selected.fullName}" /> </row> </rows> </grid> </window>
You can see:
1.) there is no problem for fixed radio-values (maybe you require a converter if your value is not String)
2.) you can use dynamic values, since you know them, while the renderingphase
/Robert
Hello Robert,
first of all thank you for your detailed explanation!
My question is a little bit different: "what when the list of elements (radios) is dynamic?"
A listbox and its items are updated when the model changes. That is great!
Also it is quite similar for comboboxes, listboxes, trees, grids etc. In all cases
we have a model and a renderer, but I do not know something similar for radiogroups.
Kind regards
/Horst
Hello Horst,
>> what when the list of elements (radios) is dynamic?
Yes, that is a problem. With forEach=${} you could only create from a list - no modification, no changes after render.
>> but I do not know something similar for radiogroups
1.) Using a small listbox
<listbox rows="3">
<listitem label="option1"/>
<listitem label="option2"/>
<listitem label="option3"/>
</listbox>
2.) Post feature-request
3.) Create/extend your own Radiogroup
Add a simple setModel(List list) and/or setModel(List list, Render render) can help.
setModel(.. List or your own Radiogroupmodel)
- remove all childs (this = Radiogroup)
- create new childs from the list/model
Of course this simple resolution is limited, but should work when you have to fill your radiogroup from javacode.
/Robert
Thanks for the
<radiogroup id="rating" selectedItem="@{controller.PersonBean.rating}">
tip - thats what I was looking for
(where did you find that?)
thanks
Florina
Hello Florina,
>> where did you find that?
Sorry, I don't know - i think it was a release note. I'm using ZK since 2.1 and @databinding since it was made..
Check also my other answer in Which Components support Databinding?.
You can see the Radiogroup in the lang-addon.xml.
/Robert
Asked: 2008-12-01 17:06:27 +0800
Seen: 1,255 times
Last updated: Dec 03 '08