You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "wmike1987@gmail.com" <wm...@gmail.com> on 2011/08/02 00:11:05 UTC

radio button example help

This code is from the wicket examples:
I'm having a lot of trouble understanding it. How is the current selection
recognized? Why does the compound property model (the Input object) not have
any getters/setters?

package org.apache.wicket.examples.compref;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.IClusterable;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;


/**
 * Page with examples on {@link
org.apache.wicket.markup.html.form.ListChoice}.
 * 
 * @author Eelco Hillenius
 */
public class RadioChoicePage extends WicketExamplePage
{
    /** available sites for selection. */
    private static final List SITES = Arrays.asList(new String[] { "The
Server Side", "Java Lobby",
            "Java.Net" });

    /**
     * Constructor
     */
    public RadioChoicePage()
    {
        final Input input = new Input();
        setModel(new CompoundPropertyModel(input));

        // Add a FeedbackPanel for displaying our messages
        FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
        add(feedbackPanel);

        // Add a form with an onSumbit implementation that sets a message
        Form form = new Form("form")
        {
            protected void onSubmit()
            {
                info("input: " + input);
            }
        };
        add(form);

        // Add a radio choice component that uses Input's 'site' property to
        // designate the
        // current selection, and that uses the SITES list for the available
        // options.
        form.add(new RadioChoice("site", SITES));
    }

    /** Simple data class that acts as a model for the input fields. */
    private static class Input implements IClusterable
    {
        /** the selected site. */
        public String site = (String)SITES.get(0);

        /**
         * @see java.lang.Object#toString()
         */
        public String toString()
        {
            return "site = '" + site + "'";
        }
    }
}

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/radio-button-example-help-tp3710953p3710953.html
Sent from the Users forum 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 button example help

Posted by Sven Meier <sv...@meiers.net>.
Hi,


wmike1987@gmail.com wrote:
> 
> How is the current selection recognized?
> 

the RadioChoice get's a PropertyModel from the CompoundPropertyModel
automagically. You could do it explicitely like the following:

  new RadioChoice("site", new PropertyModel(input, "site"), SITES);


wmike1987@gmail.com wrote:
> 
>  Why does the compound property model (the Input object) not have any
> getters/setters?
> 

Wicket's property resolver uses field access if no getter/setter is present.

Hope this helps
Sven

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/radio-button-example-help-tp3710953p3711589.html
Sent from the Users forum 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