001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.markup.html.form; 018 019import java.util.List; 020 021import org.apache.wicket.markup.ComponentTag; 022import org.apache.wicket.model.IModel; 023 024 025/** 026 * A choice implemented as a dropdown menu/list. 027 * <p> 028 * Java: 029 * 030 * <pre> 031 * List SITES = Arrays.asList(new String[] { "The Server Side", "Java Lobby", "Java.Net" }); 032 * 033 * // Add a dropdown choice component that uses Input's 'site' property to designate the 034 * // current selection, and that uses the SITES list for the available options. 035 * // Note that when the selection is null, Wicket will lookup a localized string to 036 * // represent this null with key: "id + '.null'". In this case, this is 'site.null' 037 * // which can be found in DropDownChoicePage.properties 038 * form.add(new DropDownChoice("site", SITES)); 039 * </pre> 040 * 041 * HTML: 042 * 043 * <pre> 044 * <select wicket:id="site"> 045 * <option>site 1</option> 046 * <option>site 2</option> 047 * </select> 048 * </pre> 049 * 050 * </p> 051 * 052 * @author Jonathan Locke 053 * @author Eelco Hillenius 054 * @author Johan Compagner 055 * 056 * @param <T> 057 * The model object type 058 */ 059public class DropDownChoice<T> extends AbstractSingleSelectChoice<T> 060{ 061 private static final long serialVersionUID = 1L; 062 063 /** 064 * Constructor. 065 * 066 * @param id 067 * See Component 068 */ 069 public DropDownChoice(final String id) 070 { 071 super(id); 072 } 073 074 /** 075 * Constructor. 076 * 077 * @param id 078 * See Component 079 * @param choices 080 * The collection of choices in the dropdown 081 */ 082 public DropDownChoice(final String id, final List<? extends T> choices) 083 { 084 super(id, choices); 085 } 086 087 /** 088 * Constructor. 089 * 090 * @param id 091 * See Component 092 * @param renderer 093 * The rendering engine 094 * @param choices 095 * The collection of choices in the dropdown 096 */ 097 public DropDownChoice(final String id, final List<? extends T> choices, 098 final IChoiceRenderer<? super T> renderer) 099 { 100 super(id, choices, renderer); 101 } 102 103 /** 104 * Constructor. 105 * 106 * @param id 107 * See Component 108 * @param model 109 * See Component 110 * @param choices 111 * The collection of choices in the dropdown 112 */ 113 public DropDownChoice(final String id, IModel<T> model, final List<? extends T> choices) 114 { 115 super(id, model, choices); 116 } 117 118 /** 119 * Constructor. 120 * 121 * @param id 122 * See Component 123 * @param model 124 * See Component 125 * @param choices 126 * The drop down choices 127 * @param renderer 128 * The rendering engine 129 */ 130 public DropDownChoice(final String id, IModel<T> model, final List<? extends T> choices, 131 final IChoiceRenderer<? super T> renderer) 132 { 133 super(id, model, choices, renderer); 134 } 135 136 /** 137 * Constructor. 138 * 139 * @param id 140 * See Component 141 * @param choices 142 * The collection of choices in the dropdown 143 */ 144 public DropDownChoice(String id, IModel<? extends List<? extends T>> choices) 145 { 146 super(id, choices); 147 } 148 149 /** 150 * Constructor. 151 * 152 * @param id 153 * See Component 154 * @param model 155 * See Component 156 * @param choices 157 * The drop down choices 158 */ 159 public DropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices) 160 { 161 super(id, model, choices); 162 } 163 164 /** 165 * Constructor. 166 * 167 * @param id 168 * See Component 169 * @param choices 170 * The drop down choices 171 * @param renderer 172 * The rendering engine 173 */ 174 public DropDownChoice(String id, IModel<? extends List<? extends T>> choices, 175 IChoiceRenderer<? super T> renderer) 176 { 177 super(id, choices, renderer); 178 } 179 180 /** 181 * Constructor. 182 * 183 * @param id 184 * See Component 185 * @param model 186 * See Component 187 * @param choices 188 * The drop down choices 189 * @param renderer 190 * The rendering engine 191 */ 192 public DropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices, 193 IChoiceRenderer<? super T> renderer) 194 { 195 super(id, model, choices, renderer); 196 } 197 198 /** 199 * Processes the component tag. 200 * 201 * @param tag 202 * Tag to modify 203 * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag) 204 */ 205 @Override 206 protected void onComponentTag(final ComponentTag tag) 207 { 208 checkComponentTag(tag, "select"); 209 210 super.onComponentTag(tag); 211 } 212}