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