package org.apache.wicket.examples.compref;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.util.io.IClusterable;
@link
@author
public class CheckBoxMultipleChoicePage extends WicketExamplePage
{
private static final List<String> SITES = Arrays.asList("The Server Side", "Java Lobby",
"Java.Net");
private static final List<String> MANY_CHOICES = Arrays.asList("Choice1", "Choice2", "Choice3",
"Choice4", "Choice5", "Choice6", "Choice7", "Choice8", "Choice9");
public CheckBoxMultipleChoicePage()
{
final Input input = new Input();
setDefaultModel(new CompoundPropertyModel<>(input));
FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
add(feedbackPanel);
Form<Void> form = new Form<Void>("form")
{
@Override
protected void onSubmit()
{
info("input: " + input);
}
};
add(form);
CheckBoxMultipleChoice<String> siteChoice = new CheckBoxMultipleChoice<>("sites",
SITES);
form.add(siteChoice);
CheckBoxMultipleChoice<String> manyChoice = new CheckBoxMultipleChoice<>("choices",
MANY_CHOICES);
form.add(manyChoice);
}
private static class Input implements IClusterable
{
public List<String> sites = new ArrayList<>();
public List<String> choices = new ArrayList<>();
public Input()
{
choices.add("Choice3");
choices.add("Choice4");
choices.add("Choice5");
}
@see
@Override
public String toString()
{
return "sites = '" + listAsString(sites) + "', choices='" + listAsString(choices) + "'";
}
private String listAsString(List<String> list)
{
StringBuilder b = new StringBuilder();
for (Iterator<String> i = list.iterator(); i.hasNext();)
{
b.append(i.next());
if (i.hasNext())
{
b.append(", ");
}
}
return b.toString();
}
}
@Override
protected void explain()
{
String html = "<span wicket:id=\"sites\">\n" + "</span>\n"
+ "<span wicket:id=\"choices\">\n" + "</span>";
String code = " CheckBoxMultipleChoice siteChoice = new CheckBoxMultipleChoice(\"sites\", SITES);\n"
+ " form.add(siteChoice);\n"
+ "\n"
+ " CheckBoxMultipleChoice manyChoice = new CheckBoxMultipleChoice(\"choices\", MANY_CHOICES);\n"
+ " form.add(manyChoice);";
add(new ExplainPanel(html, code));
}
}