0

Radiogroup, data binding and TypeConverter

asked 2009-02-09 20:45:48 +0800

lamh gravatar image lamh
84 3

I have a Person object that has gender field represened by an Integer.

<radiogroup id="genderGroup" selectedItem="@{person.gender, converter=UiBeanStringIntConverter}">
<radio id="female" label="female" value="4"/>
<radio id="male" label="male" value="5"/>
</radiogroup>

The UIBeanStringIntConverter implements TypeConverter and has the following code:

public Object coerceToBean(Object val, Component comp) {
return Integer.parseInt((String)val);
}

public Object coerceToUi(Object val, Component comp) {
return val.toString();
}

I am trying to convert the person.gender Integer to radio's value string. It keeps giving me the following error:

Cause: java.lang.NoSuchMethodException: class org.zkoss.zul.Radiogroup: name=selectedItem args=[class java.lang.String]
org.zkoss.zk.ui.UiException: java.lang.NoSuchMethodException: class org.zkoss.zul.Radiogroup: name=selectedItem args=[class java.lang.String]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.zkoss.lang.Classes.newInstance(Classes.java:78)
at org.zkoss.lang.Exceptions.wrap(Exceptions.java:164)
at org.zkoss.zk.ui.UiException$Aide.wrap(UiException.java:46)
at org.zkoss.zkplus.databind.Binding.myLoadAttribute(Binding.java:331)
at org.zkoss.zkplus.databind.Binding.loadAttribute(Binding.java:279)
at org.zkoss.zkplus.databind.DataBinder.loadAttrs(DataBinder.java:490)


Any idea?

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-02-09 22:23:25 +0800

robertpic71 gravatar image robertpic71
1275 1

Hi

The standardconverter for a selecteditem has to do a little bit more action - not only a simple convert.
Your converter will work i.e. for a textbox.

To extend selectedItem Converter it's always a good idea, start with the original converter from the svn.

Here it is >>> RadiogroupSelectedItemConverter <<<<.
Make a copy and customize the search and getValue-part for your use.

/Robert

link publish delete flag offensive edit

answered 2009-02-10 15:48:00 +0800

lamh gravatar image lamh
84 3

I got this to work. Thanks.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-02-09 20:45:48 +0800

Seen: 1,352 times

Last updated: Feb 10 '09

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