View Javadoc

1   /*
2    * $Id: ELErrorsTag.java 376779 2006-02-10 18:08:58Z husted $
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.strutsel.taglib.html;
19  
20  import org.apache.struts.taglib.html.ErrorsTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * <p>Custom tag that renders error messages if an appropriate request
27   * attribute has been created.  The tag looks for a request attribute with a
28   * reserved key, and assumes that it is either a String, a String array,
29   * containing message keys to be looked up in the module's MessageResources,
30   * or an object of type <code>org.apache.struts.action.ActionErrors</code>.
31   * <p> The following optional message keys will be utilized if corresponding
32   * messages exist for them in the application resources:</p>
33   *
34   * <ul>
35   *
36   * <li><b>errors.header</b> - If present, the corresponding message will be
37   * rendered prior to the individual list of error messages.</li>
38   *
39   * <li><b>errors.footer</b> - If present, the corresponding message will be
40   * rendered following the individual list of error messages.</li>
41   *
42   * <li><b>errors.prefix</b> - If present, the corresponding message will be
43   * rendered before each individual error message.</li>
44   *
45   * <li><b>errors.suffix</b> - If present, the corresponding message will be
46   * rendered after each individual error message.</li>
47   *
48   * </ul>
49   *
50   * <p> This class is a subclass of the class <code>org.apache.struts.taglib.html.ErrorsTag</code>
51   * which provides most of the described functionality.  This subclass allows
52   * all attribute values to be specified as expressions utilizing the
53   * JavaServer Pages Standard Library expression language.
54   *
55   * @version $Rev: 376779 $
56   */
57  public class ELErrorsTag extends ErrorsTag {
58      /***
59       * Instance variable mapped to "bundle" tag attribute. (Mapping set in
60       * associated BeanInfo class.)
61       */
62      private String bundleExpr;
63  
64      /***
65       * Instance variable mapped to "footer" tag attribute. (Mapping set in
66       * associated BeanInfo class.)
67       */
68      private String footerExpr;
69  
70      /***
71       * Instance variable mapped to "header" tag attribute. (Mapping set in
72       * associated BeanInfo class.)
73       */
74      private String headerExpr;
75  
76      /***
77       * Instance variable mapped to "locale" tag attribute. (Mapping set in
78       * associated BeanInfo class.)
79       */
80      private String localeExpr;
81  
82      /***
83       * Instance variable mapped to "name" tag attribute. (Mapping set in
84       * associated BeanInfo class.)
85       */
86      private String nameExpr;
87  
88      /***
89       * Instance variable mapped to "prefix" tag attribute. (Mapping set in
90       * associated BeanInfo class.)
91       */
92      private String prefixExpr;
93  
94      /***
95       * Instance variable mapped to "property" tag attribute. (Mapping set in
96       * associated BeanInfo class.)
97       */
98      private String propertyExpr;
99  
100     /***
101      * Instance variable mapped to "suffix" tag attribute. (Mapping set in
102      * associated BeanInfo class.)
103      */
104     private String suffixExpr;
105 
106     /***
107      * Getter method for "bundle" tag attribute. (Mapping set in associated
108      * BeanInfo class.)
109      */
110     public String getBundleExpr() {
111         return (bundleExpr);
112     }
113 
114     /***
115      * Getter method for "footer" tag attribute. (Mapping set in associated
116      * BeanInfo class.)
117      */
118     public String getFooterExpr() {
119         return (footerExpr);
120     }
121 
122     /***
123      * Getter method for "header" tag attribute. (Mapping set in associated
124      * BeanInfo class.)
125      */
126     public String getHeaderExpr() {
127         return (headerExpr);
128     }
129 
130     /***
131      * Getter method for "locale" tag attribute. (Mapping set in associated
132      * BeanInfo class.)
133      */
134     public String getLocaleExpr() {
135         return (localeExpr);
136     }
137 
138     /***
139      * Getter method for "name" tag attribute. (Mapping set in associated
140      * BeanInfo class.)
141      */
142     public String getNameExpr() {
143         return (nameExpr);
144     }
145 
146     /***
147      * Getter method for "prefix" tag attribute. (Mapping set in associated
148      * BeanInfo class.)
149      */
150     public String getPrefixExpr() {
151         return (prefixExpr);
152     }
153 
154     /***
155      * Getter method for "property" tag attribute. (Mapping set in associated
156      * BeanInfo class.)
157      */
158     public String getPropertyExpr() {
159         return (propertyExpr);
160     }
161 
162     /***
163      * Getter method for "suffix" tag attribute. (Mapping set in associated
164      * BeanInfo class.)
165      */
166     public String getSuffixExpr() {
167         return (suffixExpr);
168     }
169 
170     /***
171      * Setter method for "bundle" tag attribute. (Mapping set in associated
172      * BeanInfo class.)
173      */
174     public void setBundleExpr(String bundleExpr) {
175         this.bundleExpr = bundleExpr;
176     }
177 
178     /***
179      * Setter method for "footer" tag attribute. (Mapping set in associated
180      * BeanInfo class.)
181      */
182     public void setFooterExpr(String footerExpr) {
183         this.footerExpr = footerExpr;
184     }
185 
186     /***
187      * Setter method for "header" tag attribute. (Mapping set in associated
188      * BeanInfo class.)
189      */
190     public void setHeaderExpr(String headerExpr) {
191         this.headerExpr = headerExpr;
192     }
193 
194     /***
195      * Setter method for "locale" tag attribute. (Mapping set in associated
196      * BeanInfo class.)
197      */
198     public void setLocaleExpr(String localeExpr) {
199         this.localeExpr = localeExpr;
200     }
201 
202     /***
203      * Setter method for "name" tag attribute. (Mapping set in associated
204      * BeanInfo class.)
205      */
206     public void setNameExpr(String nameExpr) {
207         this.nameExpr = nameExpr;
208     }
209 
210     /***
211      * Setter method for "prefix" tag attribute. (Mapping set in associated
212      * BeanInfo class.)
213      */
214     public void setPrefixExpr(String prefixExpr) {
215         this.prefixExpr = prefixExpr;
216     }
217 
218     /***
219      * Setter method for "property" tag attribute. (Mapping set in associated
220      * BeanInfo class.)
221      */
222     public void setPropertyExpr(String propertyExpr) {
223         this.propertyExpr = propertyExpr;
224     }
225 
226     /***
227      * Setter method for "suffix" tag attribute. (Mapping set in associated
228      * BeanInfo class.)
229      */
230     public void setSuffixExpr(String suffixExpr) {
231         this.suffixExpr = suffixExpr;
232     }
233 
234     /***
235      * Resets attribute values for tag reuse.
236      */
237     public void release() {
238         super.release();
239         setBundleExpr(null);
240         setFooterExpr(null);
241         setHeaderExpr(null);
242         setLocaleExpr(null);
243         setNameExpr(null);
244         setPrefixExpr(null);
245         setPropertyExpr(null);
246         setSuffixExpr(null);
247     }
248 
249     /***
250      * Process the start tag.
251      *
252      * @throws JspException if a JSP exception has occurred
253      */
254     public int doStartTag() throws JspException {
255         evaluateExpressions();
256 
257         return (super.doStartTag());
258     }
259 
260     /***
261      * Processes all attribute values which use the JSTL expression evaluation
262      * engine to determine their values.
263      *
264      * @throws JspException if a JSP exception has occurred
265      */
266     private void evaluateExpressions()
267         throws JspException {
268         String string = null;
269 
270         if ((string =
271                 EvalHelper.evalString("bundle", getBundleExpr(), this,
272                     pageContext)) != null) {
273             setBundle(string);
274         }
275 
276         if ((string =
277                 EvalHelper.evalString("footer", getFooterExpr(), this,
278                     pageContext)) != null) {
279             setFooter(string);
280         }
281 
282         if ((string =
283                 EvalHelper.evalString("header", getHeaderExpr(), this,
284                     pageContext)) != null) {
285             setHeader(string);
286         }
287 
288         if ((string =
289                 EvalHelper.evalString("locale", getLocaleExpr(), this,
290                     pageContext)) != null) {
291             setLocale(string);
292         }
293 
294         if ((string =
295                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
296             setName(string);
297         }
298 
299         if ((string =
300                 EvalHelper.evalString("prefix", getPrefixExpr(), this,
301                     pageContext)) != null) {
302             setPrefix(string);
303         }
304 
305         if ((string =
306                 EvalHelper.evalString("property", getPropertyExpr(), this,
307                     pageContext)) != null) {
308             setProperty(string);
309         }
310 
311         if ((string =
312                 EvalHelper.evalString("suffix", getSuffixExpr(), this,
313                     pageContext)) != null) {
314             setSuffix(string);
315         }
316     }
317 }