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: TextareaTag.java,v $
31   * Revision 1.3  2005/04/09 18:04:20  colinmacleod
32   * Changed copyright text to GPL v2 explicitly.
33   *
34   * Revision 1.2  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.1  2005/01/06 23:10:07  colinmacleod
39   * Moved up a version number.
40   * Changed copyright notices to 2005.
41   * Updated the documentation:
42   *   - started working on multiproject:site docu.
43   *   - changed the logo.
44   * Added checkstyle and fixed LOADS of style issues.
45   * Added separate thirdparty subproject.
46   * Added struts (in web), util and webgui (in webtheme) from ivata op.
47   *
48   * Revision 1.4  2004/11/03 16:12:09  colinmacleod
49   * Changed fieldPath to resourceFieldPath.
50   *
51   * Revision 1.3  2004/07/13 19:48:10  colinmacleod
52   * Moved project to POJOs from EJBs.
53   * Applied PicoContainer to services layer (replacing session EJBs).
54   * Applied Hibernate to persistence layer (replacing entity EJBs).
55   *
56   * Revision 1.2  2004/03/21 21:16:35  colinmacleod
57   * Shortened name to ivata op.
58   *
59   * Revision 1.1.1.1  2004/01/27 20:59:40  colinmacleod
60   * Moved ivata op to SourceForge.
61   *
62   * Revision 1.2  2003/10/16 15:43:03  jano
63   * Fixes problems with building and some problems with splitting to subprojects
64   *
65   * Revision 1.1.1.1  2003/10/13 20:49:27  colin
66   * Restructured portal into subprojects
67   *
68   * Revision 1.4  2003/03/11 18:25:45  colin
69   * changes to allow just one webapp
70   *
71   * Revision 1.3  2003/03/03 16:57:12  colin
72   * converted localization to automatic paths
73   * added labels
74   * added mandatory fieldName attribute
75   *
76   * Revision 1.2  2003/02/28 07:33:17  colin
77   * added nobr and made the image come before the textarea
78   *
79   * Revision 1.1  2003/02/24 19:33:33  colin
80   * Moved to new subproject.
81   *
82   * Revision 1.4  2003/02/13 08:51:32  colin
83   * moved initialization from doStartTag to MaskProperties.doStartTag
84   *
85   * Revision 1.3  2003/01/30 07:52:44  colin
86   * bugfixes in mandatory handling
87   *
88   * Revision 1.2  2003/01/27 08:26:21  colin
89   * SSLEXT & i18n changes
90   *
91   * Revision 1.1  2003/01/18 20:32:08  colin
92   * added html struts override tags and help
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>&lt;textarea&gt;</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             // if it is not read-only, use the standard struts implementation
210             JspWriter out = pageContext.getOut();
211         }
212         if (maskProperties.getReadOnly()) {
213             return SKIP_BODY;
214         } else {
215             // if it is not read-only, use the standard struts implementation
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         // if it is read only, just put out the current text contents, formatted
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              * HttpSession session = request.getSession(); SettingsRemote
248              * settings = (SettingsRemote)session.getAttribute("settings");
249              * String userName = (String)session.getAttribute("userName");
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