1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.taglib.form;
24
25 import java.io.IOException;
26
27 import javax.servlet.jsp.JspException;
28
29 /**
30 * Implementation of select form control tag.
31 *
32 * @author Jose M. Palomar
33 * @version $Revision: 130 $
34 */
35 public final class SelectTag extends BaseControlTag {
36
37
38 /**
39 * <code>size</code> attribute.
40 */
41 private String size;
42
43 /**
44 * <code>multiple</code> attribute.
45 */
46 private boolean multiple;
47
48
49 /**
50 * Creates a new <code>SelectTag</code> object.
51 */
52 public SelectTag() {
53 }
54
55
56 /**
57 * Process the start tag for this instance.
58 *
59 * @return int EVAL_BODY_INCLUDE.
60 * @throws JspException if somethign goes wrong during processing.
61 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
62 */
63 public int doStartTag() throws JspException {
64
65 try {
66 pageContext.getOut().print(renderSelectStartElement());
67 }
68 catch (IOException ioe) {
69
70 }
71
72 return EVAL_BODY_INCLUDE;
73
74 }
75
76 /**
77 * Process the end tag for this instance.
78 *
79 * @return int EVAL_PAGE.
80 * @throws JspException if somethign goes wrong during processing.
81 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
82 */
83 public int doEndTag() throws JspException {
84
85 try {
86 pageContext.getOut().print(renderSelectEndElement());
87 }
88 catch (IOException ioe) {
89
90 }
91
92 return EVAL_PAGE;
93 }
94
95
96 /**
97 * Renders select start tag.
98 *
99 * @return String a string containing rendered select start tag.
100 */
101 public String renderSelectStartElement() {
102
103 StringBuffer element = new StringBuffer();
104
105 element.append("<select");
106
107 element.append(baseAttributes());
108 element.append(controlName());
109 element.append(controlAttributes());
110
111 if (size != null) {
112 element.append(" size=\"");
113 element.append(size);
114 element.append("\"");
115 }
116
117 if (multiple) {
118 element.append(" multiple");
119 }
120
121 element.append(controlEvents());
122 element.append(intrinsicEvents());
123
124 element.append(">");
125
126 return element.toString();
127
128 }
129
130 /**
131 * Renders select end tag.
132 *
133 * @return String a string containing rendered select end tag.
134 */
135 public String renderSelectEndElement() {
136 return "</select>";
137 }
138
139
140 /**
141 * Sets <code>multiple</code> attribute value.
142 *
143 * @param multiple String <code>multiple</code> attribute value.
144 */
145 public void setMultiple(String multiple) {
146 this.multiple = multiple.equals("true");
147 }
148
149 /**
150 * Sets <code>size</code> attribute value.
151 *
152 * @param size String <code>size</code> attribute value.
153 */
154 public void setSize(String size) {
155 this.size = size;
156 }
157
158 /**
159 * Called on a Tag handler to release state.
160 *
161 * @see javax.servlet.jsp.tagext.Tag#release()
162 */
163 public void release() {
164
165 super.release();
166
167 this.size = null;
168 this.multiple = false;
169
170 }
171
172 }