-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I have a form with textbox e radiogroup. In this form I insert/delete/update records from MySQL
The table structure of MySQL is:
Utente varchar(15)
...
Utente_attivo bit <--- for TRUE/FALSE
Any user inserted could be ACTIVE or INACTIVE (Utente_attivo).
I can't correctly set my radiogroup in the form ... Any idea? I can't use "value=false" ???
n.b. the textbox txtAttivo is only for "debug" mode....
thanks
User/Active user
<hbox>
<textbox width="90%" value="@{win.current.Utente}" maxlength="15" />
<textbox id="txtAttivo" width="90%" value="@{win.current.Utente_attivo}" maxlength="1" />
<radiogroup id="chkUtente_attivo" selectedItem="@{win.current.Utente_attivo}">
<radio id="chkAttivo" value="true" label="Attivo" />
<radio id="chkNonAttivo" value="false" label="Non attivo" />
</radiogroup>
</hbox>
@Robert
It works! You are the best! Thank you
Here it is:
my test.zul:
<?page title="Index" contentType="text/html;charset=UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <zscript> boolean test = true; </zscript> <window id="testWin" title="Index" border="normal"> <vbox> <radiogroup selectedItem="@{test, converter=webtests.binder.RadiogroupBooleanConverter}"> <radio label="Yes" value="true"/> <radio label="No" value="false"/> </radiogroup> <label id="hide" value="@{test}"/> </vbox> </window> </zk>
The converter:
package webtests.binder; /* {{IS_NOTE Purpose: Description: History: Mon Mar 12 11:05:43 2007, Created by Henri }}IS_NOTE Copyright (C) 2007 Potix Corporation. All Rights Reserved. {{IS_RIGHT }}IS_RIGHT */ import java.util.Iterator; import org.zkoss.zk.ui.Component; import org.zkoss.zkplus.databind.TypeConverter; import org.zkoss.zul.Radio; import org.zkoss.zul.Radiogroup; /** * Convert Radiogroup selected item to radio value and vice versa. * modified for boolean * * zk's RadiogroupSelectedListItemConverter modified for boolean * @author Henri */ public class RadiogroupBooleanConverter implements TypeConverter, java.io.Serializable { private static final long serialVersionUID = -7692059172828069699L; public Object coerceToUi(Object val, Component comp) { //load if (val != null && val instanceof Boolean) { Boolean bval = (Boolean) val; //iterate to find the selected radio via the value for (Iterator it = comp.getChildren().iterator(); it.hasNext();) { final Component child = (Component)it.next(); if (child instanceof Radio) { if (bval.toString().equalsIgnoreCase(((Radio)child).getValue())) { return child; } } else if (!(child instanceof Radiogroup)) { //skip nested radiogroup //bug 2464484 final Object value = coerceToUi(val, child); //recursive if (value != null) { return value; } } } } return null; } public Object coerceToBean(Object val, Component comp) { //save return val != null ? Boolean.parseBoolean(((Radio)val).getValue()) : null; } }
Hi Robert, are you news for my problem?
Thanks
Ok, thanks Roberts..
I have some meetings now. I'll post my converter later.
/Robert
I tried to use the converter RadiogroupSelectedItemConverter but my form return this error:
Cause: Not a child: <Radio null>
org.zkoss.zk.ui.UiException: Not a child: <Radio null>
at org.zkoss.zul.Radiogroup.setSelectedItem(Radiogroup.java:161)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.zkoss.zk.ui.metainfo.Property.assign0(Property.java:260)
at org.zkoss.zk.ui.metainfo.Property.assign(Property.java:175)
at org.zkoss.zk.ui.metainfo.ComponentInfo.applyProperties(ComponentInfo.java:769)
at org.zkoss.zk.ui.impl.AbstractUiFactory.newComponent(AbstractUiFactory.java:95)
...
Code in .zul form:
<radiogroup id="chkUtente_attivo" selectedItem="@{win.current.Utente_attivo}, converter=RadiogroupSelectedItemConverter()"
onCheck="onCheckUtente_attivo(self, self.selectedItem.id)">
<radio id="chkAttivo" value = "1" label="Attivo" />
<radio id="chkNonAttivo" value = "0" label="Non attivo" />
</radiogroup>
Sorry but I have recently started to use zk and often I am in trouble ...
Thanks Robert. I will read tomorrow your link...
Asked: 2009-05-13 16:51:27 +0800
Seen: 862 times
Last updated: May 15 '09