1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 package com.ivata.mask.web.tag.html;
73 import javax.servlet.jsp.JspException;
74
75 import org.apache.struts.taglib.TagUtils;
76
77 import com.ivata.mask.web.format.HTMLFormatter;
78 /***
79 * <p>
80 * Overrides an HTML <code><option></code> tag, by overriding the class
81 * from <strong>Struts </strong>.
82 * </p>
83 *
84 * <p>
85 * <b>Tag attributes: </b> <br/><table cellpadding='2' cellspacing='5'
86 * border='0' align='center' width='85%'>
87 * <tr class='TableHeadingColor'>
88 * <th>attribute</th>
89 * <th>reqd.</th>
90 * <th>param. class</th>
91 * <th width='100%'>description</th>
92 * </tr>
93 * <tr>
94 * <td>title</td>
95 * <td>false</td>
96 * <td><code>java.lang.String</code></td>
97 * <td>Title or tool-tip to be displayed when the mouse is over this option.
98 * </td>
99 * </tr>
100 * <tr>
101 * <td>readOnly</td>
102 * <td>false</td>
103 * <td><code>boolean</code></td>
104 * <td>Specifies the form elements should be displayed only and cannot be
105 * altered.</td>
106 * </tr>
107 * <tr>
108 * <td>valueKey</td>
109 * <td>true</td>
110 * <td><code>java.lang.String</code></td>
111 * <td>Specifies the localized text to use when the field is read-only.</td>
112 * </tr>
113 * </table>
114 * </p>
115 *
116 * <p>
117 * <b>Note: </b> all the tag attributes from {@link
118 * org.apache.struts.taglib.html.OptionTag Stuts} are also included.
119 * </p>
120 *
121 * @since ivata masks 0.4 (2003-01-15)
122 * @author Colin MacLeod
123 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
124 * @version $Revision: 1.3 $ TODO: add titleKey
125 */
126 public class OptionTag extends org.apache.struts.taglib.html.OptionTag {
127 /***
128 * <p>
129 * Tooltip or title to be displayed when the mouse is over this option.
130 * </p>
131 */
132 private String title = null;
133 /***
134 * <p>
135 * Overridden to add the title attribute and set the value in text in the
136 * surrounding select tag.
137 * </p>
138 *
139 * @return <code>EVAL_PAGE</code> since we always want to evaluate the
140 * page after this tag.
141 *
142 * @throws JspException
143 * if there is an error wrting to <code>out.print()</code>
144 */
145 public int doEndTag() throws JspException {
146
147 SelectTag selectTag = (SelectTag) findAncestorWithClass(this,
148 SelectTag.class);
149 if (selectTag == null) {
150 throw new JspException(
151 "ERROR in OptionTag: no surrounding select tag found.");
152 }
153
154 StringBuffer results = new StringBuffer();
155 results.append("<option ");
156 results.append(HTMLFormatter.getAttributeNotNull("class", this
157 .getStyleClass()));
158 results.append(HTMLFormatter.getBooleanAttribute("disabled", this
159 .getDisabled()));
160 results.append(HTMLFormatter.getAttributeNotNull("id", this
161 .getStyleId()));
162 results.append(HTMLFormatter.getBooleanAttribute("selected", selectTag
163 .isMatched(getValue())));
164 results.append(HTMLFormatter.getAttributeNotNull("style", this
165 .getStyle()));
166 results.append(HTMLFormatter.getAttributeNotNull("title", title));
167 results.append(HTMLFormatter.getAttributeNotNull("value", this
168 .getValue()));
169 results.append(">");
170 String text = text();
171 if (text == null) {
172 text = getValue();
173 }
174
175 if (selectTag.isMatched(getValue())) {
176 selectTag.setValueText(text);
177 }
178 results.append(text);
179 results.append("</option>");
180
181 TagUtils.getInstance().write(pageContext, results.toString());
182
183 return (EVAL_PAGE);
184 }
185 /***
186 * <p>
187 * Tooltip or title to be displayed when the mouse is over this option.
188 * </p>
189 *
190 * @return the current value of title.
191 */
192 public String getTitle() {
193 return title;
194 }
195 /***
196 * <p>
197 * Tooltip or title to be displayed when the mouse is over this option.
198 * </p>
199 *
200 * @param titleParam
201 * the new value of title.
202 */
203 public final void setTitle(final String titleParam) {
204 this.title = titleParam;
205 }
206 }
207