View Javadoc

1   /*
2    * Copyright (c) 2001 - 2005 ivata limited.
3    * All rights reserved.
4    * -----------------------------------------------------------------------------
5    * ivata masks may be redistributed under the GNU General Public
6    * License as published by the Free Software Foundation;
7    * version 2 of the License.
8    *
9    * These programs are free software; you can redistribute them and/or
10   * modify them under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; version 2 of the License.
12   *
13   * These programs are distributed in the hope that they will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16   *
17   * See the GNU General Public License in the file LICENSE.txt for more
18   * details.
19   *
20   * If you would like a copy of the GNU General Public License write to
21   *
22   * Free Software Foundation, Inc.
23   * 59 Temple Place - Suite 330
24   * Boston, MA 02111-1307, USA.
25   *
26   *
27   * To arrange commercial support and licensing, contact ivata at
28   *                  http://www.ivata.com/contact.jsp
29   * -----------------------------------------------------------------------------
30   * $Log: CheckboxTag.java,v $
31   * Revision 1.5  2005/04/11 15:07:21  colinmacleod
32   * Added a getter for label.
33   *
34   * Revision 1.4  2005/04/09 18:04:20  colinmacleod
35   * Changed copyright text to GPL v2 explicitly.
36   *
37   * Revision 1.3  2005/03/10 10:45:38  colinmacleod
38   * Fixes for tomcat4. Changed setters and getters
39   * to both use the same types.
40   *
41   * Revision 1.2  2005/01/19 13:14:03  colinmacleod
42   * Renamed CausedByException to SystemException.
43   *
44   * Revision 1.1  2005/01/06 23:10:05  colinmacleod
45   * Moved up a version number.
46   * Changed copyright notices to 2005.
47   * Updated the documentation:
48   *   - started working on multiproject:site docu.
49   *   - changed the logo.
50   * Added checkstyle and fixed LOADS of style issues.
51   * Added separate thirdparty subproject.
52   * Added struts (in web), util and webgui (in webtheme) from ivata op.
53   *
54   * Revision 1.5  2004/12/23 21:01:31  colinmacleod
55   * Updated Struts to v1.2.4.
56   * Changed base classes to use ivata masks.
57   *
58   * Revision 1.4  2004/11/03 16:12:09  colinmacleod
59   * Changed fieldPath to resourceFieldPath.
60   *
61   * Revision 1.3  2004/07/13 19:48:10  colinmacleod
62   * Moved project to POJOs from EJBs.
63   * Applied PicoContainer to services layer (replacing session EJBs).
64   * Applied Hibernate to persistence layer (replacing entity EJBs).
65   *
66   * Revision 1.2  2004/03/21 21:16:35  colinmacleod
67   * Shortened name to ivata op.
68   *
69   * Revision 1.1.1.1  2004/01/27 20:59:38  colinmacleod
70   * Moved ivata op to SourceForge.
71   *
72   * Revision 1.3  2003/10/17 12:32:18  jano
73   * fixing bugs
74   *
75   * Revision 1.2  2003/10/16 15:43:03  jano
76   * Fixes problems with building and some problems with splitting to subprojects
77   *
78   * Revision 1.1.1.1  2003/10/13 20:49:23  colin
79   * Restructured portal into subprojects
80   *
81   * Revision 1.3  2003/03/05 11:45:49  peter
82   * value defaults to true now
83   *
84   * Revision 1.2  2003/03/03 16:57:12  colin
85   * converted localization to automatic paths
86   * added labels
87   * added mandatory fieldName attribute
88   *
89   * Revision 1.1  2003/02/24 19:33:33  colin
90   * Moved to new subproject.
91   *
92   * Revision 1.1  2003/02/13 10:53:10  colin
93   * first version in CVS
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>&lt;input type=checkbox&gt;</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         // TODO: handle read-only here
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 }