001: /*
002: * $Id: ELErrorsTag.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.strutsel.taglib.html;
022:
023: import org.apache.struts.taglib.html.ErrorsTag;
024: import org.apache.strutsel.taglib.utils.EvalHelper;
025:
026: import javax.servlet.jsp.JspException;
027:
028: /**
029: * <p>Custom tag that renders error messages if an appropriate request
030: * attribute has been created. The tag looks for a request attribute with a
031: * reserved key, and assumes that it is either a String, a String array,
032: * containing message keys to be looked up in the module's MessageResources,
033: * or an object of type <code>org.apache.struts.action.ActionErrors</code>.
034: * <p> The following optional message keys will be utilized if corresponding
035: * messages exist for them in the application resources:</p>
036: *
037: * <ul>
038: *
039: * <li><b>errors.header</b> - If present, the corresponding message will be
040: * rendered prior to the individual list of error messages.</li>
041: *
042: * <li><b>errors.footer</b> - If present, the corresponding message will be
043: * rendered following the individual list of error messages.</li>
044: *
045: * <li><b>errors.prefix</b> - If present, the corresponding message will be
046: * rendered before each individual error message.</li>
047: *
048: * <li><b>errors.suffix</b> - If present, the corresponding message will be
049: * rendered after each individual error message.</li>
050: *
051: * </ul>
052: *
053: * <p> This class is a subclass of the class <code>org.apache.struts.taglib.html.ErrorsTag</code>
054: * which provides most of the described functionality. This subclass allows
055: * all attribute values to be specified as expressions utilizing the
056: * JavaServer Pages Standard Library expression language.
057: *
058: * @version $Rev: 471754 $
059: */
060: public class ELErrorsTag extends ErrorsTag {
061: /**
062: * Instance variable mapped to "bundle" tag attribute. (Mapping set in
063: * associated BeanInfo class.)
064: */
065: private String bundleExpr;
066:
067: /**
068: * Instance variable mapped to "footer" tag attribute. (Mapping set in
069: * associated BeanInfo class.)
070: */
071: private String footerExpr;
072:
073: /**
074: * Instance variable mapped to "header" tag attribute. (Mapping set in
075: * associated BeanInfo class.)
076: */
077: private String headerExpr;
078:
079: /**
080: * Instance variable mapped to "locale" tag attribute. (Mapping set in
081: * associated BeanInfo class.)
082: */
083: private String localeExpr;
084:
085: /**
086: * Instance variable mapped to "name" tag attribute. (Mapping set in
087: * associated BeanInfo class.)
088: */
089: private String nameExpr;
090:
091: /**
092: * Instance variable mapped to "prefix" tag attribute. (Mapping set in
093: * associated BeanInfo class.)
094: */
095: private String prefixExpr;
096:
097: /**
098: * Instance variable mapped to "property" tag attribute. (Mapping set in
099: * associated BeanInfo class.)
100: */
101: private String propertyExpr;
102:
103: /**
104: * Instance variable mapped to "suffix" tag attribute. (Mapping set in
105: * associated BeanInfo class.)
106: */
107: private String suffixExpr;
108:
109: /**
110: * Getter method for "bundle" tag attribute. (Mapping set in associated
111: * BeanInfo class.)
112: */
113: public String getBundleExpr() {
114: return (bundleExpr);
115: }
116:
117: /**
118: * Getter method for "footer" tag attribute. (Mapping set in associated
119: * BeanInfo class.)
120: */
121: public String getFooterExpr() {
122: return (footerExpr);
123: }
124:
125: /**
126: * Getter method for "header" tag attribute. (Mapping set in associated
127: * BeanInfo class.)
128: */
129: public String getHeaderExpr() {
130: return (headerExpr);
131: }
132:
133: /**
134: * Getter method for "locale" tag attribute. (Mapping set in associated
135: * BeanInfo class.)
136: */
137: public String getLocaleExpr() {
138: return (localeExpr);
139: }
140:
141: /**
142: * Getter method for "name" tag attribute. (Mapping set in associated
143: * BeanInfo class.)
144: */
145: public String getNameExpr() {
146: return (nameExpr);
147: }
148:
149: /**
150: * Getter method for "prefix" tag attribute. (Mapping set in associated
151: * BeanInfo class.)
152: */
153: public String getPrefixExpr() {
154: return (prefixExpr);
155: }
156:
157: /**
158: * Getter method for "property" tag attribute. (Mapping set in associated
159: * BeanInfo class.)
160: */
161: public String getPropertyExpr() {
162: return (propertyExpr);
163: }
164:
165: /**
166: * Getter method for "suffix" tag attribute. (Mapping set in associated
167: * BeanInfo class.)
168: */
169: public String getSuffixExpr() {
170: return (suffixExpr);
171: }
172:
173: /**
174: * Setter method for "bundle" tag attribute. (Mapping set in associated
175: * BeanInfo class.)
176: */
177: public void setBundleExpr(String bundleExpr) {
178: this .bundleExpr = bundleExpr;
179: }
180:
181: /**
182: * Setter method for "footer" tag attribute. (Mapping set in associated
183: * BeanInfo class.)
184: */
185: public void setFooterExpr(String footerExpr) {
186: this .footerExpr = footerExpr;
187: }
188:
189: /**
190: * Setter method for "header" tag attribute. (Mapping set in associated
191: * BeanInfo class.)
192: */
193: public void setHeaderExpr(String headerExpr) {
194: this .headerExpr = headerExpr;
195: }
196:
197: /**
198: * Setter method for "locale" tag attribute. (Mapping set in associated
199: * BeanInfo class.)
200: */
201: public void setLocaleExpr(String localeExpr) {
202: this .localeExpr = localeExpr;
203: }
204:
205: /**
206: * Setter method for "name" tag attribute. (Mapping set in associated
207: * BeanInfo class.)
208: */
209: public void setNameExpr(String nameExpr) {
210: this .nameExpr = nameExpr;
211: }
212:
213: /**
214: * Setter method for "prefix" tag attribute. (Mapping set in associated
215: * BeanInfo class.)
216: */
217: public void setPrefixExpr(String prefixExpr) {
218: this .prefixExpr = prefixExpr;
219: }
220:
221: /**
222: * Setter method for "property" tag attribute. (Mapping set in associated
223: * BeanInfo class.)
224: */
225: public void setPropertyExpr(String propertyExpr) {
226: this .propertyExpr = propertyExpr;
227: }
228:
229: /**
230: * Setter method for "suffix" tag attribute. (Mapping set in associated
231: * BeanInfo class.)
232: */
233: public void setSuffixExpr(String suffixExpr) {
234: this .suffixExpr = suffixExpr;
235: }
236:
237: /**
238: * Resets attribute values for tag reuse.
239: */
240: public void release() {
241: super .release();
242: setBundleExpr(null);
243: setFooterExpr(null);
244: setHeaderExpr(null);
245: setLocaleExpr(null);
246: setNameExpr(null);
247: setPrefixExpr(null);
248: setPropertyExpr(null);
249: setSuffixExpr(null);
250: }
251:
252: /**
253: * Process the start tag.
254: *
255: * @throws JspException if a JSP exception has occurred
256: */
257: public int doStartTag() throws JspException {
258: evaluateExpressions();
259:
260: return (super .doStartTag());
261: }
262:
263: /**
264: * Processes all attribute values which use the JSTL expression evaluation
265: * engine to determine their values.
266: *
267: * @throws JspException if a JSP exception has occurred
268: */
269: private void evaluateExpressions() throws JspException {
270: String string = null;
271:
272: if ((string = EvalHelper.evalString("bundle", getBundleExpr(),
273: this , pageContext)) != null) {
274: setBundle(string);
275: }
276:
277: if ((string = EvalHelper.evalString("footer", getFooterExpr(),
278: this , pageContext)) != null) {
279: setFooter(string);
280: }
281:
282: if ((string = EvalHelper.evalString("header", getHeaderExpr(),
283: this , pageContext)) != null) {
284: setHeader(string);
285: }
286:
287: if ((string = EvalHelper.evalString("locale", getLocaleExpr(),
288: this , pageContext)) != null) {
289: setLocale(string);
290: }
291:
292: if ((string = EvalHelper.evalString("name", getNameExpr(),
293: this , pageContext)) != null) {
294: setName(string);
295: }
296:
297: if ((string = EvalHelper.evalString("prefix", getPrefixExpr(),
298: this , pageContext)) != null) {
299: setPrefix(string);
300: }
301:
302: if ((string = EvalHelper.evalString("property",
303: getPropertyExpr(), this , pageContext)) != null) {
304: setProperty(string);
305: }
306:
307: if ((string = EvalHelper.evalString("suffix", getSuffixExpr(),
308: this, pageContext)) != null) {
309: setSuffix(string);
310: }
311: }
312: }
|