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