Beispiel für ein Wicket-Dropdownfeld - DropDownChoice
In Wicket können Sie "DropDownChoice" verwenden, um eine Dropdown-Box-Komponente zu rendern.
//Java import org.apache.wicket.markup.html.form.DropDownChoice; ... //choices in dropdown box private static final ListSEARCH_ENGINES = Arrays.asList(new String[] { "Google", "Bing", "Baidu" }); //variable to hold the selected value from dropdown box, //and also make "Google" is selected by default private String selected = "Google"; DropDownChoice listSites = new DropDownChoice ( "sites", new PropertyModel (this, "selected"), SEARCH_ENGINES); //HTML for dropdown box
1. Wicket DropDownChoice Beispiel
Beispiel für die Anzeige des Dropdown-Felds über „DropDownChoice
“ und die Standardeinstellung eines ausgewählten Werts.
import java.util.Arrays; import java.util.List; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.form.DropDownChoice; 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.PropertyModel; public class DropDownChoicePage extends WebPage { private static final ListSEARCH_ENGINES = Arrays.asList(new String[] { "Google", "Bing", "Baidu" }); //make Google selected by default private String selected = "Google"; public DropDownChoicePage(final PageParameters parameters) { add(new FeedbackPanel("feedback")); DropDownChoice listSites = new DropDownChoice ( "sites", new PropertyModel (this, "selected"), SEARCH_ENGINES); Form> form = new Form ("form") { @Override protected void onSubmit() { info("Selected search engine : " + selected); } }; add(form); form.add(listSites); } }
2. Wicket-HTML-Seite
Seite zum Rendern einer Dropdown-Box.
Wicket DropDownChoice example
3. Demo
Start und Besuch -http://localhost:8080/WicketExamples/
"Google" ist standardmäßig ausgewählt.
Wählen Sie "Baidu" und klicken Sie auf die Display-Schaltfläche.
Laden Sie es herunter -Wicket-DropDownChoice-Example.zip (7 KB)