Hi Goran,

I have a form with a radio group. Everithing works (page renders without
errors) but I can't get selected radio in forms onSubmit method.
model.getSomeRadioGroup() returns null.

It probably some logical error using the models. Does radioGroup have to
have its own model or something like that.

RadioGroup does need to have its own model and it also needs to be included in the markup and it needs to wrap (be the parent) of the specific radio's.

If your radio's are directly adjacent in the markup you might find the RadioChoice class easier since you can just set 1 model and pass in a list of the options.

Here is simplified example:

public SomeForm(String id) {
  super(id, new CompoundPropertyModel(new SomeModel()));
  RadioGroup radioGroup = new RadioGroup("someRadioGroup");
  radioGroup.add(new Radio("radio1"));
  radioGroup.add(new Radio("radio2"));
  radioGroup.add(new Radio("radio3"));
You need to set a model value for each radio since wicket will do a radioGroup.modelObject = selectedRadio.modelObject when the form is submitted.

protected void onSubmit() {
  SomeModel model = (SomeModel) getModelObject();
  System.out.println(model.getSomeRadioGroup()); // This returns null
  System.out.println(model.getRadio1());// This returns null
  System.out.println(model.getRadio2());// This returns null
  System.out.println(model.getRadio3());// This returns null    

public class EmailSettingsModel {

        private String radio1;

        private String radio2;

        private String radio3;

        private String someRadioGroup;

        //... plus getters and setters

I would change this so that the options for the radio were and enumeration:

public enum EmailOptions { OPTION_1, OPTION_2, OPTION_3; }

then just use a regular Model to hold the values:

public SomeForm(String id) {
 super(id, new CompoundPropertyModel(new Model()));
 RadioGroup radioGroup = new RadioGroup("someRadioGroup", new Model 
 radioGroup.add(new EmailOptionRadio("radio1", new Model 
 radioGroup.add(new EmailOptionRadio("radio2", new Model 
 radioGroup.add(new EmailOptionRadio("radio3",  new Model 

Where emailOptionRadio overrides the Component.getConverter(Class c) method to 
return an IConverter for the EmailOptions enumeration like:

/* (non-Javadoc)
         * @see org.apache.wicket.Component#getConverter(java.lang.Class)
        public IConverter getConverter(Class type) {

                return new IConverter () {

                        /* (non-Javadoc)
                         * @see 
                        public Object convertToObject(String value, Locale 
locale) {

                                if (value.equals("1")) {
                                        return EmailOptions.OPTION_1;
else if (value.equals("2")) {
                                        return EmailOptions.OPTION_2;
                                if (value.equals("3")) {
                                        return EmailOptions.OPTION_3;
                                else return null;

                        /* (non-Javadoc)
                         * @see 
                        public String convertToString(Object value, Locale 
locale) {

                                EmailOptions opts = (EmailOptions)value;

if (opts == EmailOptions.OPTION_1) return "1"; if (opts == EmailOptions.OPTION_2) return "2";

if (opts == EmailOptions.OPTION_3) return "3";

                                else return "";


<form wicket:id="form">

  <input wicket:id="radio1" type="radio"/>
  <input wicket:id="radio2" type="radio"/>
  <input wicket:id="radio3" type="radio"/>



To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to