KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > html > ELErrorsTag


1 /*
2  * $Id: ELErrorsTag.java 123585 2004-12-29 00:43:33Z martinc $
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
19 package org.apache.strutsel.taglib.html;
20
21 import org.apache.struts.taglib.html.ErrorsTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import org.apache.strutsel.taglib.utils.EvalHelper;
24
25 /**
26  * Custom tag that renders error messages if an appropriate request attribute
27  * has been created. The tag looks for a request attribute with a reserved
28  * key, and assumes that it is either a String, a String array, containing
29  * message keys to be looked up in the module's MessageResources, or
30  * an object of type <code>org.apache.struts.action.ActionErrors</code>.
31  * <p>
32  * The following optional message keys will be utilized if corresponding
33  * messages exist for them in the application resources:
34  * <ul>
35  * <li><b>errors.header</b> - If present, the corresponding message will be
36  * rendered prior to the individual list of error messages.</li>
37  * <li><b>errors.footer</b> - If present, the corresponding message will be
38  * rendered following the individual list of error messages.</li>
39  * <li><b>errors.prefix</b> - If present, the corresponding message will be
40  * rendered before each individual error message.</li>
41  * <li><b>errors.suffix</b> - If present, the corresponding message will be
42  * rendered after each individual error message.</li>
43  * </ul>
44  *<p>
45  * This class is a subclass of the class
46  * <code>org.apache.struts.taglib.html.ErrorsTag</code> which provides most of
47  * the described functionality. This subclass allows all attribute values to
48  * be specified as expressions utilizing the JavaServer Pages Standard Library
49  * expression language.
50  *
51  * @version $Rev: 123585 $
52  */

53 public class ELErrorsTag extends ErrorsTag {
54
55     /**
56      * Instance variable mapped to "bundle" tag attribute.
57      * (Mapping set in associated BeanInfo class.)
58      */

59     private String JavaDoc bundleExpr;
60     /**
61      * Instance variable mapped to "footer" tag attribute.
62      * (Mapping set in associated BeanInfo class.)
63      */

64     private String JavaDoc footerExpr;
65     /**
66      * Instance variable mapped to "header" tag attribute.
67      * (Mapping set in associated BeanInfo class.)
68      */

69     private String JavaDoc headerExpr;
70     /**
71      * Instance variable mapped to "locale" tag attribute.
72      * (Mapping set in associated BeanInfo class.)
73      */

74     private String JavaDoc localeExpr;
75     /**
76      * Instance variable mapped to "name" tag attribute.
77      * (Mapping set in associated BeanInfo class.)
78      */

79     private String JavaDoc nameExpr;
80     /**
81      * Instance variable mapped to "prefix" tag attribute.
82      * (Mapping set in associated BeanInfo class.)
83      */

84     private String JavaDoc prefixExpr;
85     /**
86      * Instance variable mapped to "property" tag attribute.
87      * (Mapping set in associated BeanInfo class.)
88      */

89     private String JavaDoc propertyExpr;
90     /**
91      * Instance variable mapped to "suffix" tag attribute.
92      * (Mapping set in associated BeanInfo class.)
93      */

94     private String JavaDoc suffixExpr;
95
96     /**
97      * Getter method for "bundle" tag attribute.
98      * (Mapping set in associated BeanInfo class.)
99      */

100     public String JavaDoc getBundleExpr() { return (bundleExpr); }
101     /**
102      * Getter method for "footer" tag attribute.
103      * (Mapping set in associated BeanInfo class.)
104      */

105     public String JavaDoc getFooterExpr() { return (footerExpr); }
106     /**
107      * Getter method for "header" tag attribute.
108      * (Mapping set in associated BeanInfo class.)
109      */

110     public String JavaDoc getHeaderExpr() { return (headerExpr); }
111     /**
112      * Getter method for "locale" tag attribute.
113      * (Mapping set in associated BeanInfo class.)
114      */

115     public String JavaDoc getLocaleExpr() { return (localeExpr); }
116     /**
117      * Getter method for "name" tag attribute.
118      * (Mapping set in associated BeanInfo class.)
119      */

120     public String JavaDoc getNameExpr() { return (nameExpr); }
121     /**
122      * Getter method for "prefix" tag attribute.
123      * (Mapping set in associated BeanInfo class.)
124      */

125     public String JavaDoc getPrefixExpr() { return (prefixExpr); }
126     /**
127      * Getter method for "property" tag attribute.
128      * (Mapping set in associated BeanInfo class.)
129      */

130     public String JavaDoc getPropertyExpr() { return (propertyExpr); }
131     /**
132      * Getter method for "suffix" tag attribute.
133      * (Mapping set in associated BeanInfo class.)
134      */

135     public String JavaDoc getSuffixExpr() { return (suffixExpr); }
136
137     /**
138      * Setter method for "bundle" tag attribute.
139      * (Mapping set in associated BeanInfo class.)
140      */

141     public void setBundleExpr(String JavaDoc bundleExpr) { this.bundleExpr = bundleExpr; }
142     /**
143      * Setter method for "footer" tag attribute.
144      * (Mapping set in associated BeanInfo class.)
145      */

146     public void setFooterExpr(String JavaDoc footerExpr) { this.footerExpr = footerExpr; }
147     /**
148      * Setter method for "header" tag attribute.
149      * (Mapping set in associated BeanInfo class.)
150      */

151     public void setHeaderExpr(String JavaDoc headerExpr) { this.headerExpr = headerExpr; }
152     /**
153      * Setter method for "locale" tag attribute.
154      * (Mapping set in associated BeanInfo class.)
155      */

156     public void setLocaleExpr(String JavaDoc localeExpr) { this.localeExpr = localeExpr; }
157     /**
158      * Setter method for "name" tag attribute.
159      * (Mapping set in associated BeanInfo class.)
160      */

161     public void setNameExpr(String JavaDoc nameExpr) { this.nameExpr = nameExpr; }
162     /**
163      * Setter method for "prefix" tag attribute.
164      * (Mapping set in associated BeanInfo class.)
165      */

166     public void setPrefixExpr(String JavaDoc prefixExpr) { this.prefixExpr = prefixExpr; }
167     /**
168      * Setter method for "property" tag attribute.
169      * (Mapping set in associated BeanInfo class.)
170      */

171     public void setPropertyExpr(String JavaDoc propertyExpr) { this.propertyExpr = propertyExpr; }
172     /**
173      * Setter method for "suffix" tag attribute.
174      * (Mapping set in associated BeanInfo class.)
175      */

176     public void setSuffixExpr(String JavaDoc suffixExpr) { this.suffixExpr = suffixExpr; }
177
178     /**
179      * Resets attribute values for tag reuse.
180      */

181     public void release()
182     {
183         super.release();
184         setBundleExpr(null);
185         setFooterExpr(null);
186         setHeaderExpr(null);
187         setLocaleExpr(null);
188         setNameExpr(null);
189         setPrefixExpr(null);
190         setPropertyExpr(null);
191         setSuffixExpr(null);
192     }
193     
194     /**
195      * Process the start tag.
196      *
197      * @exception JspException if a JSP exception has occurred
198      */

199     public int doStartTag() throws JspException JavaDoc {
200         evaluateExpressions();
201         return(super.doStartTag());
202     }
203
204     /**
205      * Processes all attribute values which use the JSTL expression evaluation
206      * engine to determine their values.
207      *
208      * @exception JspException if a JSP exception has occurred
209      */

210     private void evaluateExpressions() throws JspException JavaDoc {
211         String JavaDoc string = null;
212
213         if ((string = EvalHelper.evalString("bundle", getBundleExpr(),
214                                             this, pageContext)) != null)
215             setBundle(string);
216
217         if ((string = EvalHelper.evalString("footer", getFooterExpr(),
218                                             this, pageContext)) != null)
219             setFooter(string);
220
221         if ((string = EvalHelper.evalString("header", getHeaderExpr(),
222                                             this, pageContext)) != null)
223             setHeader(string);
224
225         if ((string = EvalHelper.evalString("locale", getLocaleExpr(),
226                                             this, pageContext)) != null)
227             setLocale(string);
228
229         if ((string = EvalHelper.evalString("name", getNameExpr(),
230                                             this, pageContext)) != null)
231             setName(string);
232
233         if ((string = EvalHelper.evalString("prefix", getPrefixExpr(),
234                                             this, pageContext)) != null)
235             setPrefix(string);
236
237         if ((string = EvalHelper.evalString("property", getPropertyExpr(),
238                                             this, pageContext)) != null)
239             setProperty(string);
240
241         if ((string = EvalHelper.evalString("suffix", getSuffixExpr(),
242                                             this, pageContext)) != null)
243             setSuffix(string);
244     }
245 }
246
Popular Tags