Wicketドロップダウンボックスの例– DropDownChoice
Wicketでは、「DropDownChoice」を使用してドロップダウンボックスコンポーネントをレンダリングできます。
//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の例
「DropDownChoice
」を介してドロップダウンボックスを表示し、デフォルトで選択した値を表示する例。
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ページ
ドロップダウンボックスをレンダリングするページ。
Wicket DropDownChoice example
3. Demo
デフォルトでは「Google」が選択されています。
「Baidu」を選択し、表示ボタンをクリックします。
ダウンロード–Wicket-DropDownChoice-Example.zip(7KB)