You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Cristina <cr...@acm.org> on 2008/10/05 01:54:57 UTC

Re: Radio group, model

Hi Goran,

it looks like there's an easier way to use a RadioGroup. As the javadoc
states, "... The model object of the group is set to the model object of the
selected radio component or null if none selected". So you can just do the
following, for instance:

(a) WebPage class:

    private enum Option { CREATE, UPDATE };

(b) Form class:

        [...]
        private RadioGroup options;
        [...]

(c) Form constructor:

            [...]
            options = new RadioGroup("options", new Model());
            options.add(new Radio("create", new Model(Option.CREATE)));
            options.add(new Radio("update", new Model(Option.UPDATE)));
            add(options);
            [...]

(d) onSubmit() method:

            String option = options.getModelObjectAsString();
            if (option.equals(Option.CREATE)) {
                [...]
            } else { // UPDATE...
                [...]
            }

(e) HTML file:

    [...]
    <input type="radio" wicket:id="create">Create Document</input>
    <input type="radio" wicket:id="update">Update Document</input>
    [...]

Hope this helps,

Cristina



Goran Novak wrote:
> 
> Thanks,
> 
> I got it to work but I dont't understand why does RadioGroup has to have
> its own model. RadioGroup has a constructor "RadioGroup(java.lang.String
> id)", why does it exist if you can't create RadioGroup without its own
> model. It seems somewhat misleading.
> 
> Here is the solution if someone else encounters this problem:
> 
> [...]
> 

-- 
View this message in context: http://www.nabble.com/Radio-group%2C-model-tp16678100p19819311.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Radio group, model

Posted by Cristina <cr...@acm.org>.
A small but important correction... :-)

(e) HTML file: both radio buttons must be under a *span* tag enclosing the
attribute-value pair *wicket:id="options"*.

Cristina

-- 
View this message in context: http://www.nabble.com/Radio-group%2C-model-tp16678100p19831786.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org