-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
I have radio button Yes/No with form binding as follows
<radiogroup id="addresstop" selectedItem="@bind(fx.printaddres)">
<radio id="top1" label="Yes" value="1" />
<radio id="top2" label="No" value="0" />
</radiogroup>
printaddress is defined as int in the database. The problem is when i select yes, it is correctly storing value 1 in the database, when again when i open the screen , it is not selecting the Yes Radio button
I requested this to be fixed a while back... http://forum.zkoss.org/question/80397/how-can-i-bind-an-int-value-to-radiogroup-for-selecteditem-it-wants-string/
Issue is the radio button doesn't work with an int :( Has to be a string... so you can fix this various ways...
I just added a getter and setter on VM getPrintAddress() returns String version..... setPrintAddress() converts my form String to my model's int.
Annoying I know.
Hi Thank you.
I have written the converter as follows. But just wondering how can i call this in the value property as per above example
package com.product.webapp.component;
import org.zkoss.bind.BindContext; import org.zkoss.bind.Converter; import org.zkoss.zk.ui.Component;
public class MyRadioButtonConverter implements Converter { /** * Convert Date to String. * * @param val * date to be converted * @param comp * associated component * @param ctx * bind context for associate Binding and extra parameter (e.g. * format) * @return the converted String */
/**
* The method coerceToUi() is invoked when loading ViewModel's property to
* component and its return type should correspond to bound component
* attribute's value[1]. The coerceToBean() is invoked when saving. If you
* only need to one way conversion, you can leave unused method empty.
*/
public Object coerceToUi(Object val, Component comp, BindContext ctx) {
String strI = String.valueOf(val);
return strI;
}
/**
* Convert String to Integer.
*
* @param val
* date in string form
* @param comp
* associated component
* @param ctx
* bind context for associate Binding and extra parameter (e.g.
* format)
* @return the converted Date
*/
public Object coerceToBean(Object val, Component comp, BindContext ctx) {
return Integer.parseInt((String) val);
}
}
Asked: 2013-10-03 03:47:05 +0800
Seen: 154 times
Last updated: Oct 03 '13