Beispiel für mehrere Kontrollkästchen in Wicket - CheckBoxMultipleChoice
Wicket-Beispiel zum Erstellen vonmultiples select checkboxes und automatisches Aktivieren des Kontrollkästchens.
//Java import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice; ... //checkboxes value to display private static final ListLANGUAGES = Arrays.asList(new String[] { "Java", ".NET", "PHP", "Ruby", "C/C++" }); //variable to hold the checkbox values private ArrayList languagesSelect = new ArrayList (); final CheckBoxMultipleChoice listLanguages = new CheckBoxMultipleChoice ( "languages", new Model(languagesSelect), LANGUAGES); //HTML
1. Wicket mehrere Kontrollkästchen Beispiel
Beispiel, um mehrere Kontrollkästchen über „CheckBoxMultipleChoice“ anzuzeigen und automatisch zu aktivieren. Der Code sollte selbsterklärend sein.
Datei: CheckBoxMultipleChoicePage.java
package com.example.user;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.PageParameters;
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.markup.html.WebPage;
import org.apache.wicket.model.Model;
public class CheckBoxMultipleChoicePage extends WebPage {
private static final List LANGUAGES = Arrays.asList(new String[] {
"Java", ".NET", "PHP", "Ruby", "C/C++" });
private static final List HOSTING_TYPES = Arrays
.asList(new String[] { "Shared Host", "VPS", "Clound Host",
"Dedicated Server" });
// hold the checkbox values
private ArrayList languagesSelect = new ArrayList();
// checked vps and dedicated server by default
private ArrayList hostingtSelect = new ArrayList(
Arrays.asList(new String[] { "VPS", "Dedicated Server" }));
public CheckBoxMultipleChoicePage(final PageParameters parameters) {
add(new FeedbackPanel("feedback"));
final CheckBoxMultipleChoice listLanguages =
new CheckBoxMultipleChoice(
"languages", new Model(languagesSelect), LANGUAGES);
final CheckBoxMultipleChoice listHosting =
new CheckBoxMultipleChoice(
"hostings", new Model(hostingtSelect), HOSTING_TYPES);
Form> form = new Form("userForm") {
@Override
protected void onSubmit() {
info("Languages : " + languagesSelect.toString());
info("Hosting Types : " + hostingtSelect.toString());
}
};
add(form);
form.add(listLanguages);
form.add(listHosting);
}
}
2. Wicket-HTML-Seite
Seite zum Rendern mehrerer Kontrollkästchen.
Datei: CheckBoxMultipleChoicePage.html
Wicket CheckBoxMultipleChoice Example
3. Demo
Start und Besuch -http://localhost:8080/WicketExamples/
Standardmäßig sind "VPS" und "Dedicated Server" aktiviert.

Aktivieren Sie einige Kontrollkästchen und klicken Sie auf die Schaltfläche zum Anzeigen.

Laden Sie es herunter -Wicket-CheckBoxMultipleChoice-Examples.zip (8 KB)