01: package com.opensymphony.webwork.components;
02:
03: import com.opensymphony.xwork.util.OgnlValueStack;
04:
05: import javax.servlet.http.HttpServletRequest;
06: import javax.servlet.http.HttpServletResponse;
07:
08: /**
09: * <!-- START SNIPPET: javadoc -->
10: * The combo box is basically an HTML INPUT of type text and HTML SELECT grouped together to give you a combo box
11: * functionality. You can place text in the INPUT control by using the SELECT control or type it in directly in
12: * the text field.<p/>
13: *
14: * In this example, the SELECT will be populated from id=year attribute. Counter is itself an Iterator. It will
15: * span from first to last. The population is done via javascript, and requires that this tag be surrounded by a
16: * <form>.<p/>
17: *
18: * Note that unlike the <ww:select/> tag, there is no ability to define the individual <option> tags' id attribute
19: * or content separately. Each of these is simply populated from the toString() method of the list item. Presumably
20: * this is because the select box isn't intended to actually submit useful data, but to assist the user in filling
21: * out the text field.<p/>
22: * <!-- END SNIPPET: javadoc -->
23: *
24: * <p/> <b>Examples</b>
25: *
26: * <pre>
27: * <!-- START SNIPPET: example -->
28: * JSP:
29: * <ww:bean name="webwork.util.Counter" id="year">
30: * <ww:param name="first" value="text('firstBirthYear')"/>
31: * <ww:param name="last" value="2000"/>
32: *
33: * <ww:combobox label="Birth year" size="6" maxlength="4" name="birthYear" list="#year"/>
34: * </ww:bean>
35: *
36: * Velocity:
37: * #tag( ComboBox "label=Birth year" "size=6" "maxlength=4" "name=birthYear" "list=#year" )
38: * <!-- END SNIPPET: example -->
39: * </pre>
40: *
41: * @author Patrick Lightbody
42: * @author Rene Gielen
43: * @version $Revision: 2468 $
44: * @since 2.2
45: *
46: * @ww.tag name="combobox" tld-body-content="JSP" tld-tag-class="com.opensymphony.webwork.views.jsp.ui.ComboBoxTag"
47: * description="Widget that fills a text box from a select"
48: */
49: public class ComboBox extends TextField {
50: final public static String TEMPLATE = "combobox";
51:
52: protected String list;
53:
54: public ComboBox(OgnlValueStack stack, HttpServletRequest request,
55: HttpServletResponse response) {
56: super (stack, request, response);
57: }
58:
59: protected String getDefaultTemplate() {
60: return TEMPLATE;
61: }
62:
63: public void evaluateExtraParams() {
64: super .evaluateExtraParams();
65:
66: if (list != null) {
67: addParameter("list", findValue(list));
68: }
69: }
70:
71: /**
72: * Iteratable source to populate from. If this is missing, the select widget is simply not displayed.
73: * @ww.tagattribute required="true"
74: */
75: public void setList(String list) {
76: this.list = list;
77: }
78: }
|