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: SubmitTag.java,v $
31   * Revision 1.5  2005/04/26 14:47:19  colinmacleod
32   * No longer displays when printing.
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:04  colinmacleod
42   * Renamed CausedByException to SystemException.
43   *
44   * Revision 1.1  2005/01/06 23:10:07  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.4  2004/11/03 16:12:09  colinmacleod
55   * Changed fieldPath to resourceFieldPath.
56   *
57   * Revision 1.3  2004/07/13 19:48:10  colinmacleod
58   * Moved project to POJOs from EJBs.
59   * Applied PicoContainer to services layer (replacing session EJBs).
60   * Applied Hibernate to persistence layer (replacing entity EJBs).
61   *
62   * Revision 1.2  2004/03/21 21:16:35  colinmacleod
63   * Shortened name to ivata op.
64   *
65   * Revision 1.1.1.1  2004/01/27 20:59:40  colinmacleod
66   * Moved ivata op to SourceForge.
67   *
68   * Revision 1.2  2003/10/16 15:43:03  jano
69   * Fixes problems with building and some problems with splitting to subprojects
70   *
71   * Revision 1.1.1.1  2003/10/13 20:49:27  colin
72   * Restructured portal into subprojects
73   *
74   * Revision 1.2  2003/03/03 16:57:12  colin
75   * converted localization to automatic paths
76   * added labels
77   * added mandatory fieldName attribute
78   *
79   * Revision 1.1  2003/02/24 19:33:33  colin
80   * Moved to new subproject.
81   *
82   * Revision 1.6  2003/02/24 09:49:26  colin
83   * added args for i18n keys
84   *
85   * Revision 1.5  2003/02/14 10:08:35  colin
86   * applied maskProperties.doStartTag
87   *
88   * Revision 1.4  2003/02/04 17:43:51  colin
89   * copyright notice
90   *
91   * Revision 1.3  2003/01/30 07:52:44  colin
92   * bugfixes in mandatory handling
93   *
94   * Revision 1.2  2003/01/27 08:26:21  colin
95   * SSLEXT & i18n changes
96   *
97   * Revision 1.1  2003/01/18 20:32:08  colin
98   * added html struts override tags and help
99   * -----------------------------------------------------------------------------
100  */
101 package com.ivata.mask.web.tag.html;
102 import java.util.List;
103 
104 import javax.servlet.jsp.JspException;
105 /***
106  * <p>
107  * Overrides an HTML <code>&lt;input type=submit&gt;</code> tag, by overriding
108  * the class from <strong>Struts </strong>.
109  * </p>
110  *
111  * <p>
112  * <b>Tag attributes: </b> <br/><table cellpadding='2' cellspacing='5'
113  * border='0' align='center' width='85%'>
114  * <tr class='TableHeadingColor'>
115  * <th>attribute</th>
116  * <th>reqd.</th>
117  * <th>param. class</th>
118  * <th width='100%'>description</th>
119  * </tr>
120  * <tr>
121  * <td>fieldName</td>
122  * <td>true</td>
123  * <td><code>java.lang.String</code></td>
124  * <td>The field name is used to default the following attributes of the tag:
125  * <br/>
126  * <ul>
127  * <li><code>styleId</code></li>
128  * <li><code>titleKey</code></li>
129  * <li><code>valueKey</code></li>
130  * </ul>.</td>
131  * </tr>
132  * <tr>
133  * <td>readOnly</td>
134  * <td>false</td>
135  * <td><code>boolean</code></td>
136  * <td>Specifies whether or not this submit button should be shown. If
137  * <code>true</code>, the submit button is not shown.</td>
138  * </tr>
139  * <tr>
140  * <td>titleKey</td>
141  * <td>true</td>
142  * <td><code>java.lang.String</code></td>
143  * <td>Specifies the localized text to use for mouse-over events.</td>
144  * </tr>
145  * <tr>
146  * <td>valueKey</td>
147  * <td>true</td>
148  * <td><code>java.lang.String</code></td>
149  * <td>Specifies the localized text to use for the button text.</td>
150  * </tr>
151  * </table>
152  * </p>
153  *
154  * <p>
155  * <b>Note: </b> all the tag attributes from {@link
156  * org.apache.struts.taglib.SubmitTag Stuts} are included.
157  * </p>
158  *
159  * @since ivata masks 0.4 (2003-01-15)
160  * @author Colin MacLeod
161  * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
162  * @version $Revision: 1.5 $
163  */
164 public class SubmitTag extends org.apache.struts.taglib.html.SubmitTag {
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         // if this is read only, do nothing
185         if (maskProperties.getReadOnly()
186                 || (pageContext.getRequest().getParameter("print") != null)) {
187             maskProperties.reset(this);
188             return EVAL_PAGE;
189         }
190         int returnValue = super.doEndTag();
191         maskProperties.reset(this);
192         return returnValue;
193     }
194     /***
195      * <p>
196      * Overridden to set the value and title strings to the values represented
197      * by the localized keys in this class.
198      * </p>
199      *
200      * @return value returned by superclass method.
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 this is read only, do nothing
209         if (maskProperties.getReadOnly()) {
210             return SKIP_BODY;
211         }
212         return super.doStartTag();
213     }
214     /***
215      * <p>
216      * Calls {@link MaskProperties#getBundleMaskProperites.getBundle}.
217      * </p>
218      *
219      * @return the current value of bundle.
220      */
221     public final String getBundle() {
222         return maskProperties.getBundle();
223     }
224     /***
225      * <p>
226      * Stores and maintains <strong>ivata op </strong> specific mask properties.
227      * </p>
228      *
229      * @return the current value of maskProperties.
230      */
231     public MaskProperties getMaskProperties() {
232         return maskProperties;
233     }
234     public final List getTitleArgs() {
235         return maskProperties.getTitleArgs();
236     }
237     public final List getValueArgs() {
238         return maskProperties.getValueArgs();
239     }
240     /***
241      * <p>
242      * >Name of the field to which this label refers. This is used in
243      * conjunction with the <code>resourceFieldPath</code> to retrieve the
244      * correct message resources path.
245      * </p>
246      *
247      * @param fieldName
248      *            the new value of fieldName.
249      */
250     public void setFieldName(final String fieldName) {
251         maskProperties.setFieldName(fieldName);
252     }
253     /***
254      * <p>
255      * Stores and maintains <strong>ivata op </strong> specific mask properties.
256      * </p>
257      *
258      * @param maskPropertiesParam
259      *            the new value of maskProperties.
260      */
261     public void setMaskProperties(final MaskProperties maskPropertiesParam) {
262         this.maskProperties = maskPropertiesParam;
263     }
264     /***
265      * <p>
266      * Specifies whether or not this button should be shown, If this attribute
267      * is unset, the button will decide whether or not to dispaly on the basis
268      * of the <code>readOnly</code> attribute of the surrounding form.
269      * </p>
270      *
271      * @param readOnly
272      *            <code>true</code> if the button should always be shown,
273      *            otherwise the button will only be shown if the surrounding
274      *            form is not read-only.
275      */
276     public void setReadOnly(final boolean readOnly) {
277         maskProperties.setReadOnly(readOnly);
278     }
279     /***
280      * Refer to {@link MaskProperties#setTitleArgs}.
281      *
282      * @param args Refer to {@link MaskProperties#setTitleArgs}.
283      */
284     public final void setTitleArgs(final List args) {
285         maskProperties.setTitleArgs(args);
286     }
287     /***
288      * <p>
289      * Set the value of the key used to localize the title tag attribute.
290      * </p>
291      *
292      * @param titleKey
293      *            the new value of titleKey.
294      */
295     public final void setTitleKey(final String titleKey) {
296         maskProperties.setTitleKey(titleKey);
297     }
298     /***
299      * Refer to {@link MaskProperties#setValueArgs}.
300      *
301      * @param args Refer to {@link MaskProperties#setValueArgs}.
302      */
303     public final void setValueArgs(final List args) {
304         maskProperties.setValueArgs(args);
305     }
306     /***
307      * <p>
308      * Set the value of the key used to localize the value tag attribute.
309      * </p>
310      *
311      * @param valueKey
312      *            the new value of valueKey.
313      */
314     public void setValueKey(final String valueKey) {
315         maskProperties.setValueKey(valueKey);
316     }
317 }
318