001: /*
002: * $Id: ELMessagesTag.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.MessagesTag;
024: import org.apache.strutsel.taglib.utils.EvalHelper;
025:
026: import javax.servlet.jsp.JspException;
027:
028: /**
029: * Custom tag that iterates the elements of a message collection. It defaults
030: * to retrieving the messages from <code>Action.ERROR_KEY</code>, but if the
031: * message attribute is set to true then the messages will be retrieved from
032: * <code>Action.MESSAGE_KEY</code>. This is an alternative to the default
033: * <code>ErrorsTag</code>. <p> This class is a subclass of the class
034: * <code>org.apache.struts.taglib.html.MessagesTag</code> which provides most
035: * of the described functionality. This subclass allows all attribute values
036: * to be specified as expressions utilizing the JavaServer Pages Standard
037: * Library expression language.
038: *
039: * @version $Rev: 471754 $
040: */
041: public class ELMessagesTag extends MessagesTag {
042: /**
043: * Instance variable mapped to "id" tag attribute. (Mapping set in
044: * associated BeanInfo class.)
045: */
046: private String idExpr;
047:
048: /**
049: * Instance variable mapped to "bundle" tag attribute. (Mapping set in
050: * associated BeanInfo class.)
051: */
052: private String bundleExpr;
053:
054: /**
055: * Instance variable mapped to "locale" tag attribute. (Mapping set in
056: * associated BeanInfo class.)
057: */
058: private String localeExpr;
059:
060: /**
061: * Instance variable mapped to "name" tag attribute. (Mapping set in
062: * associated BeanInfo class.)
063: */
064: private String nameExpr;
065:
066: /**
067: * Instance variable mapped to "property" tag attribute. (Mapping set in
068: * associated BeanInfo class.)
069: */
070: private String propertyExpr;
071:
072: /**
073: * Instance variable mapped to "header" tag attribute. (Mapping set in
074: * associated BeanInfo class.)
075: */
076: private String headerExpr;
077:
078: /**
079: * Instance variable mapped to "footer" tag attribute. (Mapping set in
080: * associated BeanInfo class.)
081: */
082: private String footerExpr;
083:
084: /**
085: * Instance variable mapped to "message" tag attribute. (Mapping set in
086: * associated BeanInfo class.)
087: */
088: private String messageExpr;
089:
090: /**
091: * Getter method for "id" tag attribute. (Mapping set in associated
092: * BeanInfo class.)
093: */
094: public String getIdExpr() {
095: return (idExpr);
096: }
097:
098: /**
099: * Getter method for "bundle" tag attribute. (Mapping set in associated
100: * BeanInfo class.)
101: */
102: public String getBundleExpr() {
103: return (bundleExpr);
104: }
105:
106: /**
107: * Getter method for "locale" tag attribute. (Mapping set in associated
108: * BeanInfo class.)
109: */
110: public String getLocaleExpr() {
111: return (localeExpr);
112: }
113:
114: /**
115: * Getter method for "name" tag attribute. (Mapping set in associated
116: * BeanInfo class.)
117: */
118: public String getNameExpr() {
119: return (nameExpr);
120: }
121:
122: /**
123: * Getter method for "property" tag attribute. (Mapping set in associated
124: * BeanInfo class.)
125: */
126: public String getPropertyExpr() {
127: return (propertyExpr);
128: }
129:
130: /**
131: * Getter method for "header" tag attribute. (Mapping set in associated
132: * BeanInfo class.)
133: */
134: public String getHeaderExpr() {
135: return (headerExpr);
136: }
137:
138: /**
139: * Getter method for "footer" tag attribute. (Mapping set in associated
140: * BeanInfo class.)
141: */
142: public String getFooterExpr() {
143: return (footerExpr);
144: }
145:
146: /**
147: * Getter method for "message" tag attribute. (Mapping set in associated
148: * BeanInfo class.)
149: */
150: public String getMessageExpr() {
151: return (messageExpr);
152: }
153:
154: /**
155: * Setter method for "id" tag attribute. (Mapping set in associated
156: * BeanInfo class.)
157: */
158: public void setIdExpr(String idExpr) {
159: this .idExpr = idExpr;
160: }
161:
162: /**
163: * Setter method for "bundle" tag attribute. (Mapping set in associated
164: * BeanInfo class.)
165: */
166: public void setBundleExpr(String bundleExpr) {
167: this .bundleExpr = bundleExpr;
168: }
169:
170: /**
171: * Setter method for "locale" tag attribute. (Mapping set in associated
172: * BeanInfo class.)
173: */
174: public void setLocaleExpr(String localeExpr) {
175: this .localeExpr = localeExpr;
176: }
177:
178: /**
179: * Setter method for "name" tag attribute. (Mapping set in associated
180: * BeanInfo class.)
181: */
182: public void setNameExpr(String nameExpr) {
183: this .nameExpr = nameExpr;
184: }
185:
186: /**
187: * Setter method for "property" tag attribute. (Mapping set in associated
188: * BeanInfo class.)
189: */
190: public void setPropertyExpr(String propertyExpr) {
191: this .propertyExpr = propertyExpr;
192: }
193:
194: /**
195: * Setter method for "header" tag attribute. (Mapping set in associated
196: * BeanInfo class.)
197: */
198: public void setHeaderExpr(String headerExpr) {
199: this .headerExpr = headerExpr;
200: }
201:
202: /**
203: * Setter method for "footer" tag attribute. (Mapping set in associated
204: * BeanInfo class.)
205: */
206: public void setFooterExpr(String footerExpr) {
207: this .footerExpr = footerExpr;
208: }
209:
210: /**
211: * Setter method for "message" tag attribute. (Mapping set in associated
212: * BeanInfo class.)
213: */
214: public void setMessageExpr(String messageExpr) {
215: this .messageExpr = messageExpr;
216: }
217:
218: /**
219: * Resets attribute values for tag reuse.
220: */
221: public void release() {
222: super .release();
223: setIdExpr(null);
224: setBundleExpr(null);
225: setLocaleExpr(null);
226: setNameExpr(null);
227: setPropertyExpr(null);
228: setHeaderExpr(null);
229: setFooterExpr(null);
230: setMessageExpr(null);
231: }
232:
233: /**
234: * Process the start tag.
235: *
236: * @throws JspException if a JSP exception has occurred
237: */
238: public int doStartTag() throws JspException {
239: evaluateExpressions();
240:
241: return (super .doStartTag());
242: }
243:
244: /**
245: * Processes all attribute values which use the JSTL expression evaluation
246: * engine to determine their values.
247: *
248: * @throws JspException if a JSP exception has occurred
249: */
250: private void evaluateExpressions() throws JspException {
251: String string = null;
252:
253: if ((string = EvalHelper.evalString("id", getIdExpr(), this ,
254: pageContext)) != null) {
255: setId(string);
256: }
257:
258: if ((string = EvalHelper.evalString("bundle", getBundleExpr(),
259: this , pageContext)) != null) {
260: setBundle(string);
261: }
262:
263: if ((string = EvalHelper.evalString("locale", getLocaleExpr(),
264: this , pageContext)) != null) {
265: setLocale(string);
266: }
267:
268: if ((string = EvalHelper.evalString("name", getNameExpr(),
269: this , pageContext)) != null) {
270: setName(string);
271: }
272:
273: if ((string = EvalHelper.evalString("property",
274: getPropertyExpr(), this , pageContext)) != null) {
275: setProperty(string);
276: }
277:
278: if ((string = EvalHelper.evalString("header", getHeaderExpr(),
279: this , pageContext)) != null) {
280: setHeader(string);
281: }
282:
283: if ((string = EvalHelper.evalString("footer", getFooterExpr(),
284: this , pageContext)) != null) {
285: setFooter(string);
286: }
287:
288: if ((string = EvalHelper.evalString("message",
289: getMessageExpr(), this, pageContext)) != null) {
290: setMessage(string);
291: }
292: }
293: }
|