package org.apache.wicket.examples.compref;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.util.io.IClusterable;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
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;
@link
@author
public class RadioChoicePage extends WicketExamplePage
{
private static final List<String> SITES = Arrays.asList("The Server Side", "Java Lobby", "Java.Net");
public RadioChoicePage()
{
final Input input = new Input();
setDefaultModel(new CompoundPropertyModel<>(input));
final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
feedbackPanel.setOutputMarkupId(true);
add(feedbackPanel);
Form<Void> form = new Form<Void>("form")
{
@Override
protected void onSubmit()
{
info("input: " + input);
}
};
add(form);
RadioChoice<String> sites = new RadioChoice<>("site", SITES);
sites.add(new AjaxFormChoiceComponentUpdatingBehavior()
{
@Override
protected void onUpdate(AjaxRequestTarget target)
{
info("Selected: " + getComponent().getDefaultModelObjectAsString());
target.add(feedbackPanel);
}
});
form.add(sites);
}
private static class Input implements IClusterable
{
public String site = SITES.get(0);
@see
@Override
public String toString()
{
return "site = '" + site + "'";
}
}
@Override
protected void explain()
{
String html = "<span valign=\"top\" wicket:id=\"site\">\n"
+ " <input type=\"radio\">site 1</input>\n"
+ " <input type=\"radio\">site 2</input>\n" + "</span>";
String code = "private static final List SITES = Arrays.asList(new String[] { \"The Server Side\", \"Java Lobby\", \"Java.Net\" });\n"
+ "...\n"
+ " // Add a radio choice component that uses the model object's 'site' property to designate the\n"
+ " // current selection, and that uses the SITES list for the available options.\n"
+ " form.add(new RadioChoice(\"site\", SITES));";
add(new ExplainPanel(html, code));
}
}