KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ELMessagesTag.java 54933 2004-10-16 17:04:52Z germuska $
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.MessagesTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import org.apache.strutsel.taglib.utils.EvalHelper;
24
25 /**
26  * Custom tag that iterates the elements of a message collection.
27  * It defaults to retrieving the messages from <code>Action.ERROR_KEY</code>,
28  * but if the message attribute is set to true then the messages will be
29  * retrieved from <code>Action.MESSAGE_KEY</code>. This is an alternative
30  * to the default <code>ErrorsTag</code>.
31  *<p>
32  * This class is a subclass of the class
33  * <code>org.apache.struts.taglib.html.MessagesTag</code> which provides most of
34  * the described functionality. This subclass allows all attribute values to
35  * be specified as expressions utilizing the JavaServer Pages Standard Library
36  * expression language.
37  *
38  * @version $Rev: 54933 $
39  */

40 public class ELMessagesTag extends MessagesTag {
41
42     /**
43      * Instance variable mapped to "id" tag attribute.
44      * (Mapping set in associated BeanInfo class.)
45      */

46     private String JavaDoc idExpr;
47     /**
48      * Instance variable mapped to "bundle" tag attribute.
49      * (Mapping set in associated BeanInfo class.)
50      */

51     private String JavaDoc bundleExpr;
52     /**
53      * Instance variable mapped to "locale" tag attribute.
54      * (Mapping set in associated BeanInfo class.)
55      */

56     private String JavaDoc localeExpr;
57     /**
58      * Instance variable mapped to "name" tag attribute.
59      * (Mapping set in associated BeanInfo class.)
60      */

61     private String JavaDoc nameExpr;
62     /**
63      * Instance variable mapped to "property" tag attribute.
64      * (Mapping set in associated BeanInfo class.)
65      */

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

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

76     private String JavaDoc footerExpr;
77     /**
78      * Instance variable mapped to "message" tag attribute.
79      * (Mapping set in associated BeanInfo class.)
80      */

81     private String JavaDoc messageExpr;
82
83     /**
84      * Getter method for "id" tag attribute.
85      * (Mapping set in associated BeanInfo class.)
86      */

87     public String JavaDoc getIdExpr() { return (idExpr); }
88     /**
89      * Getter method for "bundle" tag attribute.
90      * (Mapping set in associated BeanInfo class.)
91      */

92     public String JavaDoc getBundleExpr() { return (bundleExpr); }
93     /**
94      * Getter method for "locale" tag attribute.
95      * (Mapping set in associated BeanInfo class.)
96      */

97     public String JavaDoc getLocaleExpr() { return (localeExpr); }
98     /**
99      * Getter method for "name" tag attribute.
100      * (Mapping set in associated BeanInfo class.)
101      */

102     public String JavaDoc getNameExpr() { return (nameExpr); }
103     /**
104      * Getter method for "property" tag attribute.
105      * (Mapping set in associated BeanInfo class.)
106      */

107     public String JavaDoc getPropertyExpr() { return (propertyExpr); }
108     /**
109      * Getter method for "header" tag attribute.
110      * (Mapping set in associated BeanInfo class.)
111      */

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

117     public String JavaDoc getFooterExpr() { return (footerExpr); }
118     /**
119      * Getter method for "message" tag attribute.
120      * (Mapping set in associated BeanInfo class.)
121      */

122     public String JavaDoc getMessageExpr() { return (messageExpr); }
123
124     /**
125      * Setter method for "id" tag attribute.
126      * (Mapping set in associated BeanInfo class.)
127      */

128     public void setIdExpr(String JavaDoc idExpr) { this.idExpr = idExpr; }
129     /**
130      * Setter method for "bundle" tag attribute.
131      * (Mapping set in associated BeanInfo class.)
132      */

133     public void setBundleExpr(String JavaDoc bundleExpr) { this.bundleExpr = bundleExpr; }
134     /**
135      * Setter method for "locale" tag attribute.
136      * (Mapping set in associated BeanInfo class.)
137      */

138     public void setLocaleExpr(String JavaDoc localeExpr) { this.localeExpr = localeExpr; }
139     /**
140      * Setter method for "name" tag attribute.
141      * (Mapping set in associated BeanInfo class.)
142      */

143     public void setNameExpr(String JavaDoc nameExpr) { this.nameExpr = nameExpr; }
144     /**
145      * Setter method for "property" tag attribute.
146      * (Mapping set in associated BeanInfo class.)
147      */

148     public void setPropertyExpr(String JavaDoc propertyExpr) { this.propertyExpr = propertyExpr; }
149     /**
150      * Setter method for "header" tag attribute.
151      * (Mapping set in associated BeanInfo class.)
152      */

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

158     public void setFooterExpr(String JavaDoc footerExpr) { this.footerExpr = footerExpr; }
159     /**
160      * Setter method for "message" tag attribute.
161      * (Mapping set in associated BeanInfo class.)
162      */

163     public void setMessageExpr(String JavaDoc messageExpr) { this.messageExpr = messageExpr; }
164
165     /**
166      * Resets attribute values for tag reuse.
167      */

168     public void release()
169     {
170         super.release();
171         setIdExpr(null);
172         setBundleExpr(null);
173         setLocaleExpr(null);
174         setNameExpr(null);
175         setPropertyExpr(null);
176         setHeaderExpr(null);
177         setFooterExpr(null);
178         setMessageExpr(null);
179     }
180     
181     /**
182      * Process the start tag.
183      *
184      * @exception JspException if a JSP exception has occurred
185      */

186     public int doStartTag() throws JspException JavaDoc {
187         evaluateExpressions();
188         return(super.doStartTag());
189     }
190
191     /**
192      * Processes all attribute values which use the JSTL expression evaluation
193      * engine to determine their values.
194      *
195      * @exception JspException if a JSP exception has occurred
196      */

197     private void evaluateExpressions() throws JspException JavaDoc {
198         String JavaDoc string = null;
199
200         if ((string = EvalHelper.evalString("id", getIdExpr(),
201                                             this, pageContext)) != null)
202             setId(string);
203
204         if ((string = EvalHelper.evalString("bundle", getBundleExpr(),
205                                             this, pageContext)) != null)
206             setBundle(string);
207
208         if ((string = EvalHelper.evalString("locale", getLocaleExpr(),
209                                             this, pageContext)) != null)
210             setLocale(string);
211
212         if ((string = EvalHelper.evalString("name", getNameExpr(),
213                                             this, pageContext)) != null)
214             setName(string);
215
216         if ((string = EvalHelper.evalString("property", getPropertyExpr(),
217                                             this, pageContext)) != null)
218             setProperty(string);
219
220         if ((string = EvalHelper.evalString("header", getHeaderExpr(),
221                                             this, pageContext)) != null)
222             setHeader(string);
223
224         if ((string = EvalHelper.evalString("footer", getFooterExpr(),
225                                             this, pageContext)) != null)
226             setFooter(string);
227
228         if ((string = EvalHelper.evalString("message", getMessageExpr(),
229                                             this, pageContext)) != null)
230             setMessage(string);
231     }
232 }
233
Popular Tags