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 option form control tag.
31 *
32 * @author Jose M. Palomar
33 * @version $Revision: 130 $
34 */
35 public final class OptionTag extends BaseControlTag {
36
37
38 /**
39 * <code>selected</code> attribute.
40 */
41 private boolean selected;
42
43 /**
44 * <code>label</code> attribute.
45 */
46 private String label;
47
48
49 /**
50 * Creates a new <code>OptionTag</code> object.
51 */
52 public OptionTag() {
53 }
54
55
56 /**
57 * Process the start tag for this instance.
58 *
59 * @return int SKIP_BODY.
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(renderOptionStartElement());
67 pageContext.getOut().print(renderOptionEndElement());
68 }
69 catch (IOException ioe) {
70
71 }
72
73 return SKIP_BODY;
74
75 }
76
77 /**
78 * Process the end tag for this instance.
79 *
80 * @return int EVAL_PAGE.
81 * @throws JspException if somethign goes wrong during processing.
82 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
83 */
84 public int doEndTag() throws JspException {
85 return EVAL_PAGE;
86 }
87
88
89 /**
90 * Renders option start tag.
91 *
92 * @return String a string containig rendered option start tag.
93 */
94 public String renderOptionStartElement() {
95
96 StringBuffer element = new StringBuffer();
97
98 element.append("<option");
99
100 element.append(baseAttributes());
101 element.append(controlValue());
102 element.append(controlAttributes());
103
104 if (selected) {
105 element.append(" selected");
106 }
107
108 element.append(controlEvents());
109 element.append(intrinsicEvents());
110
111 element.append(">");
112
113 if (label != null) {
114 element.append(label);
115 }
116
117 return element.toString();
118
119 }
120
121 /**
122 * Renders option end tag.
123 *
124 * @return String a string containig rendered option end tag.
125 */
126 public String renderOptionEndElement() {
127 return "</option>";
128 }
129
130
131 /**
132 * Sets <code>selected</code> attribute value.
133 *
134 * @param selected String <code>selected</code> attribute value.
135 */
136 public void setSelected(String selected) {
137 this.selected = selected.equals("true");
138 }
139
140 /**
141 * Sets <code>label</code> attribute value.
142 *
143 * @param label String <code>label</code> attribute value.
144 */
145 public void setLabel(String label) {
146 this.label = label;
147 }
148
149 /**
150 * Called on a Tag handler to release state.
151 *
152 * @see javax.servlet.jsp.tagext.Tag#release()
153 */
154 public void release() {
155
156 super.release();
157
158 this.selected = false;
159 this.label = null;
160
161 }
162
163 }