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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 package com.ivata.mask.web.tag.html;
92 import java.io.IOException;
93 import javax.servlet.jsp.JspException;
94 import javax.servlet.jsp.JspWriter;
95 import com.ivata.mask.util.StringHandling;
96 import com.ivata.mask.web.format.HTMLFormatter;
97 /***
98 * <p>
99 * Overrides an HTML <code><input type=text></code> tag, by overriding
100 * the class from <strong>Struts </strong>.
101 * </p>
102 *
103 * <p>
104 * <b>Tag attributes: </b> <br/><table cellpadding='2' cellspacing='5'
105 * border='0' align='center' width='85%'>
106 * <tr class='TableHeadingColor'>
107 * <th>attribute</th>
108 * <th>reqd.</th>
109 * <th>param. class</th>
110 * <th width='100%'>description</th>
111 * </tr>
112 * <tr>
113 * <td>formatter</td>
114 * <td>false</td>
115 * <td><code>boolean</code></td>
116 * <td>Specifies a formatter to format the text if it is read-only.</td>
117 * </tr>
118 * <tr>
119 * <td>fieldName</td>
120 * <td>true</td>
121 * <td><code>java.lang.String</code></td>
122 * <td>The field name is used to default the following attributes of the tag:
123 * <br/>
124 * <ul>
125 * <li><code>styleId</code></li>
126 * <li><code>titleKey</code></li>
127 * <li><code>valueKey</code></li>
128 * </ul>.</td>
129 * </tr>
130 * <tr>
131 * <td>mandatory</td>
132 * <td>false</td>
133 * <td><code>boolean</code></td>
134 * <td>Specifies data for this tag must be entered when the form is submitted.
135 * </td>
136 * </tr>
137 * <tr>
138 * <td>readOnly</td>
139 * <td>false</td>
140 * <td><code>boolean</code></td>
141 * <td>Specifies the form elements should be displayed only and cannot be
142 * altered.</td>
143 * </tr>
144 * </table>
145 * </p>
146 *
147 * <p>
148 * <b>Note: </b> all the tag attributes from {@link
149 * org.apache.struts.taglib.TextTag Stuts} are also included.
150 * </p>
151 *
152 * @since ivata masks 0.4 (2003-01-15)
153 * @author Colin MacLeod
154 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
155 * @version $Revision: 1.3 $
156 */
157 public class TextTag extends org.apache.struts.taglib.html.TextTag {
158 /***
159 * <p>
160 * Stores and maintains <strong>ivata groupware</strong> specific mask properties.
161 * </p>
162 */
163 private MaskProperties maskProperties = new MaskProperties();
164 /***
165 * <p>
166 * Formatter used to format read-only text.
167 * </p>
168 */
169 private HTMLFormatter formatter = new HTMLFormatter();
170 /***
171 * <p>
172 * Specifies whether or not the input values can be altered.
173 * </p>
174 *
175 * @param readOnly
176 * <code>true</code> if the input of this field can be changed,
177 * otherwise <code>false</code> to only display the current
178 * value.
179 */
180 public void setReadOnly(final boolean readOnly) {
181 maskProperties.setReadOnly(readOnly);
182 }
183 /***
184 * <p>
185 * Set whether or not the value this control must be entered.
186 * </p>
187 *
188 * @param mandatory
189 * <code>true</code> if this field must be entered, otherwise
190 * <code>false</code> if the field is optional.
191 */
192 public void setMandatory(final boolean mandatory) {
193 maskProperties.setMandatory(mandatory);
194 }
195 /***
196 * <p>
197 * Overridden to provide mandatory/readony fuctionality.
198 * </p>
199 *
200 * @return value returned by superclass method, or <code>SKIP_BODY</code>
201 * if this tag is read-only.
202 *
203 * @throws JspException
204 * if either <code>valueKey</code> or <code>titleKey</code>
205 * have not been set, or as thrown by superclass method.
206 */
207 public int doStartTag() throws JspException {
208 maskProperties.doStartTag(this, pageContext);
209 if (maskProperties.getReadOnly()) {
210 return SKIP_BODY;
211 } else {
212
213 return super.doStartTag();
214 }
215 }
216 /***
217 * <p>
218 * Overridden to check whether or not the field is read only, and to apply
219 * mandatory field attributes.
220 * </p>
221 *
222 * @return <code>EVAL_PAGE</code> since we always want to evaluate the
223 * page after this tag.
224 *
225 * @throws JspException
226 * if there is an error wrting to <code>out.print()</code>
227 *
228 */
229 public int doEndTag() throws JspException {
230
231 if (maskProperties.getReadOnly()) {
232 try {
233 JspWriter out = pageContext.getOut();
234 out.print(formatter.format(StringHandling.getNotNull(
235 getValue(), "")));
236 maskProperties.reset(this);
237 return EVAL_PAGE;
238 } catch (IOException e) {
239 throw new JspException(e);
240 }
241 }
242
243 int returnValue = super.doEndTag();
244 maskProperties.reset(this);
245 return super.doEndTag();
246 }
247 /***
248 * <p>
249 * Set a formatter to use if the tag is read-only.
250 * </p>
251 *
252 * @param formatterParam
253 * new value of formatter.
254 */
255 public void setFormatter(final HTMLFormatter formatterParam) {
256 this.formatter = formatterParam;
257 }
258 /***
259 * <p>
260 * Stores and maintains <strong>ivata groupware</strong> specific mask
261 * properties.
262 * </p>
263 *
264 * @return the current value of maskProperties.
265 */
266 public MaskProperties getMaskProperties() {
267 return maskProperties;
268 }
269 /***
270 * <p>
271 * Stores and maintains <strong>ivata groupware</strong> specific mask
272 * properties.
273 * </p>
274 *
275 * @param maskPropertiesParam
276 * the new value of maskProperties.
277 */
278 public void setMaskProperties(final MaskProperties maskPropertiesParam) {
279 this.maskProperties = maskPropertiesParam;
280 }
281 /***
282 * <p>
283 * Name of the field to which this label refers. This is used in
284 * conjunction with the <code>resourceFieldPath</code> to retrieve the
285 * correct message resources path.
286 * </p>
287 *
288 * @return value of fieldName.
289 */
290 public String getFieldName() {
291 return maskProperties.getFieldName();
292 }
293 /***
294 * <p>
295 * Name of the field to which this label refers. This is used in
296 * conjunction with the <code>resourceFieldPath</code> to retrieve the
297 * correct message resources path.
298 * </p>
299 *
300 * @param fieldName
301 * the new value of fieldName.
302 */
303 public void setFieldName(final String fieldName) {
304 maskProperties.setFieldName(fieldName);
305 }
306 }
307