Exemple de cases à cocher à guichet multiple - CheckBoxMultipleChoice
Exemple de guichet pour créermultiples select checkboxes, et cocher la case automatiquement.
//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. Exemple de cases à cocher multiples
Exemple pour afficher plusieurs cases à cocher via «CheckBoxMultipleChoice», et les cocher automatiquement. Le code doit être explicite.
Fichier: 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 ListLANGUAGES = 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. Page HTML du guichet
Page pour rendre plusieurs cases à cocher.
Fichier: CheckBoxMultipleChoicePage.html
Wicket CheckBoxMultipleChoice Example
3. Demo
Démarrer et visiter -http://localhost:8080/WicketExamples/
Par défaut, "VPS" et "serveur dédié" sont cochés.
Cochez certaines cases et cliquez sur le bouton d'affichage.
Téléchargez-le -Wicket-CheckBoxMultipleChoice-Examples.zip (8 Ko)