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: MultiboxTag.java,v $
31   * Revision 1.4  2005/04/09 18:04:20  colinmacleod
32   * Changed copyright text to GPL v2 explicitly.
33   *
34   * Revision 1.3  2005/03/10 10:45:38  colinmacleod
35   * Fixes for tomcat4. Changed setters and getters
36   * to both use the same types.
37   *
38   * Revision 1.2  2005/01/19 13:14:04  colinmacleod
39   * Renamed CausedByException to SystemException.
40   *
41   * Revision 1.1  2005/01/06 23:10:06  colinmacleod
42   * Moved up a version number.
43   * Changed copyright notices to 2005.
44   * Updated the documentation:
45   *   - started working on multiproject:site docu.
46   *   - changed the logo.
47   * Added checkstyle and fixed LOADS of style issues.
48   * Added separate thirdparty subproject.
49   * Added struts (in web), util and webgui (in webtheme) from ivata op.
50   *
51   * Revision 1.6  2004/12/23 21:01:32  colinmacleod
52   * Updated Struts to v1.2.4.
53   * Changed base classes to use ivata masks.
54   *
55   * Revision 1.5  2004/11/03 16:12:09  colinmacleod
56   * Changed fieldPath to resourceFieldPath.
57   *
58   * Revision 1.4  2004/07/13 19:48:10  colinmacleod
59   * Moved project to POJOs from EJBs.
60   * Applied PicoContainer to services layer (replacing session EJBs).
61   * Applied Hibernate to persistence layer (replacing entity EJBs).
62   *
63   * Revision 1.3  2004/03/21 21:16:35  colinmacleod
64   * Shortened name to ivata op.
65   *
66   * Revision 1.2  2004/02/04 23:56:23  colinmacleod
67   * Prepared text for ivata op
68   *
69   * Revision 1.1.1.1  2004/01/27 20:59:40  colinmacleod
70   * Moved ivata op to SourceForge.
71   *
72   * Revision 1.2  2003/10/16 15:43:03  jano
73   * Fixes problems with building and some problems with splitting to subprojects
74   *
75   * Revision 1.1.1.1  2003/10/13 20:49:26  colin
76   * Restructured portal into subprojects
77   *
78   * Revision 1.1  2003/06/02 23:47:13  colin
79   * added multibox tag
80   * -----------------------------------------------------------------------------
81   */
82  package com.ivata.mask.web.tag.html;
83  import java.util.List;
84  
85  import javax.servlet.jsp.JspException;
86  import org.apache.struts.taglib.TagUtils;
87  import com.ivata.mask.util.StringHandling;
88  /***
89   * <p>
90   * Overrides an HTML <code>&lt;input type=checkbox&gt;</code> tag, by
91   * overriding the <code>multibox</code> class from <strong>Struts </strong>.
92   * </p>
93   *
94   * <p>
95   * <b>Tag attributes: </b> <br/><table cellpadding='2' cellspacing='5'
96   * border='0' align='center' width='85%'>
97   * <tr class='TableHeadingColor'>
98   * <th>attribute</th>
99   * <th>reqd.</th>
100  * <th>param. class</th>
101  * <th width='100%'>description</th>
102  * </tr>
103  * <tr>
104  * <td>fieldName</td>
105  * <td>true</td>
106  * <td><code>java.lang.String</code></td>
107  * <td>The field name is used to default the following attributes of the tag:
108  * <br/>
109  * <ul>
110  * <li><code>styleId</code></li>
111  * <li><code>titleKey</code></li>
112  * <li><code>valueKey</code></li>
113  * </ul>.</td>
114  * </tr>
115  * <tr>
116  * <td>mandatory</td>
117  * <td>false</td>
118  * <td><code>boolean</code></td>
119  * <td>Specifies data for this tag must be entered when the form is submitted.
120  * </td>
121  * </tr>
122  * <tr>
123  * <td>readOnly</td>
124  * <td>false</td>
125  * <td><code>boolean</code></td>
126  * <td>Specifies the form elements should be displayed only and cannot be
127  * altered.</td>
128  * </tr>
129  * </table>
130  * </p>
131  *
132  * <p>
133  * <b>Note: </b> all the tag attributes from {@link
134  * org.apache.struts.taglib.CheckboxTag Stuts} are also included.
135  * </p>
136  *
137  * @since ivata masks 0.4 (2003-05-22)
138  * @author Colin MacLeod
139  * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
140  * @version $Revision: 1.4 $
141  */
142 public class MultiboxTag extends org.apache.struts.taglib.html.MultiboxTag {
143     /***
144      * <p>
145      * Stores the label which is displayed to the right of the checkbox.
146      * </p>
147      */
148     private String label;
149     /***
150      * <p>
151      * Stores and maintains <strong>ivata op </strong> specific mask properties.
152      * </p>
153      */
154     private MaskProperties maskProperties = new MaskProperties();
155     /***
156      * <p>
157      * Overridden to check whether or not the field is read only, and to apply
158      * mandatory field attributes.
159      * </p>
160      *
161      * @return <code>EVAL_PAGE</code> since we always want to evaluate the
162      *         page after this tag.
163      *
164      * @throws JspException
165      *             if there is an error wrting to <code>out.print()</code>
166      *
167      */
168     public int doEndTag() throws JspException {
169         // TODO: handle read-only here
170         int returnValue = super.doEndTag();
171         if (!StringHandling.isNullOrEmpty(label)) {
172             TagUtils.getInstance().write(pageContext, " " + label);
173         }
174         maskProperties.reset(this);
175         return returnValue;
176     }
177     /***
178      * <p>
179      * Overridden to call <code>MaskProperties</code> initialization.
180      * </p>
181      *
182      * @return value returned by superclass method, or <code>SKIP_BODY</code>
183      *         if this tag is read-only.
184      *
185      * @throws JspException
186      *             if either <code>valueKey</code> or <code>titleKey</code>
187      *             have not been set, or as thrown by superclass method.
188      */
189     public int doStartTag() throws JspException {
190         maskProperties.doStartTag(this, pageContext);
191         if (this.value == null) {
192             this.value = "true";
193         }
194         return super.doStartTag();
195     }
196     public final List getLabelArgs() {
197         return maskProperties.getLabelArgs();
198     }
199     /***
200      * <p>
201      * Stores and maintains <strong>ivata op </strong> specific mask properties.
202      * </p>
203      *
204      * @return the current value of maskProperties.
205      */
206     public MaskProperties getMaskProperties() {
207         return maskProperties;
208     }
209     public final List getTitleArgs() {
210         return maskProperties.getTitleArgs();
211     }
212     /***
213      * <p>
214      * >Name of the field to which this label refers. This is used in
215      * conjunction with the <code>resourceFieldPath</code> to retrieve the
216      * correct message resources path.
217      * </p>
218      *
219      * @param fieldName
220      *            the new value of fieldName.
221      */
222     public void setFieldName(final String fieldName) {
223         maskProperties.setFieldName(fieldName);
224     }
225     /***
226      * <p>
227      * Called by <code>MaskProperties</code> to set the label.
228      * </p>
229      *
230      * @param labelParam new text to be displayed as the label.
231      */
232     public void setLabel(final String labelParam) {
233         this.label = labelParam;
234     }
235     /***
236      * Refer to {@link MaskProperties#setLabelArgs}.
237      *
238      * @param args Refer to {@link MaskProperties#setLabelArgs}.
239      */
240     public final void setLabelArgs(final List args) {
241         maskProperties.setLabelArgs(args);
242     }
243     /***
244      * <p>
245      * Localization key of a string which will appear to the right of the check
246      * box.
247      * </p>
248      *
249      * @param labelKey
250      *            the new value of labelKey.
251      */
252     public void setLabelKey(final String labelKey) {
253         maskProperties.setLabelKey(labelKey);
254     }
255     /***
256      * <p>
257      * Set whether or not the value this control must be entered.
258      * </p>
259      *
260      * @param mandatory
261      *            <code>true</code> if this field must be entered, otherwise
262      *            <code>false</code> if the field is optional.
263      */
264     public void setMandatory(final boolean mandatory) {
265         maskProperties.setMandatory(mandatory);
266     }
267     /***
268      * <p>
269      * Stores and maintains <strong>ivata op </strong> specific mask properties.
270      * </p>
271      *
272      * @param maskPropertiesParam
273      *            the new value of maskProperties.
274      */
275     public void setMaskProperties(final MaskProperties maskPropertiesParam) {
276         this.maskProperties = maskPropertiesParam;
277     }
278     /***
279      * <p>
280      * Specifies whether or not the input values can be altered.
281      * </p>
282      *
283      * @param readOnly
284      *            <code>true</code> if the input of this field can be changed,
285      *            otherwise <code>false</code> to only display the current
286      *            value.
287      */
288     public void setReadOnly(final boolean readOnly) {
289         maskProperties.setReadOnly(readOnly);
290     }
291     /***
292      * Refer to {@link MaskProperties#setTitleArgs}.
293      *
294      * @param args Refer to {@link MaskProperties#setTitleArgs}.
295      */
296     public final void setTitleArgs(final List args) {
297         maskProperties.setTitleArgs(args);
298     }
299     /***
300      * <p>
301      * Set the value of the key used to localize the title tag attribute.
302      * </p>
303      *
304      * @param titleKey
305      *            the new value of titleKey.
306      */
307     public final void setTitleKey(final String titleKey) {
308         maskProperties.setTitleKey(titleKey);
309     }
310 }
311