001: /*
002: * $Id: ELOptionsCollectionTag.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.OptionsCollectionTag;
024: import org.apache.strutsel.taglib.utils.EvalHelper;
025:
026: import javax.servlet.jsp.JspException;
027:
028: /**
029: * Tag for creating multiple <select> options from a collection. The
030: * collection may be part of the enclosing form, or may be independent of the
031: * form. Each element of the collection must expose a 'label' and a 'value',
032: * the property names of which are configurable by attributes of this tag. <p>
033: * The collection may be an array of objects, a Collection, an Enumeration, an
034: * Iterator, or a Map. <p> <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or
035: * later) platform. <p> This class is a subclass of the class
036: * <code>org.apache.struts.taglib.html.OptionsCollectionTag</code> which
037: * provides most of the described functionality. This subclass allows all
038: * attribute values to be specified as expressions utilizing the JavaServer
039: * Pages Standard Library expression language.
040: *
041: * @version $Rev: 471754 $
042: */
043: public class ELOptionsCollectionTag extends OptionsCollectionTag {
044: /**
045: * Instance variable mapped to "filter" tag attribute. (Mapping set in
046: * associated BeanInfo class.)
047: */
048: private String filterExpr;
049:
050: /**
051: * Instance variable mapped to "label" tag attribute. (Mapping set in
052: * associated BeanInfo class.)
053: */
054: private String labelExpr;
055:
056: /**
057: * Instance variable mapped to "name" tag attribute. (Mapping set in
058: * associated BeanInfo class.)
059: */
060: private String nameExpr;
061:
062: /**
063: * Instance variable mapped to "property" tag attribute. (Mapping set in
064: * associated BeanInfo class.)
065: */
066: private String propertyExpr;
067:
068: /**
069: * Instance variable mapped to "style" tag attribute. (Mapping set in
070: * associated BeanInfo class.)
071: */
072: private String styleExpr;
073:
074: /**
075: * Instance variable mapped to "styleClass" tag attribute. (Mapping set in
076: * associated BeanInfo class.)
077: */
078: private String styleClassExpr;
079:
080: /**
081: * Instance variable mapped to "value" tag attribute. (Mapping set in
082: * associated BeanInfo class.)
083: */
084: private String valueExpr;
085:
086: /**
087: * Getter method for "filter" tag attribute. (Mapping set in associated
088: * BeanInfo class.)
089: */
090: public String getFilterExpr() {
091: return (filterExpr);
092: }
093:
094: /**
095: * Getter method for "label" tag attribute. (Mapping set in associated
096: * BeanInfo class.)
097: */
098: public String getLabelExpr() {
099: return (labelExpr);
100: }
101:
102: /**
103: * Getter method for "name" tag attribute. (Mapping set in associated
104: * BeanInfo class.)
105: */
106: public String getNameExpr() {
107: return (nameExpr);
108: }
109:
110: /**
111: * Getter method for "property" tag attribute. (Mapping set in associated
112: * BeanInfo class.)
113: */
114: public String getPropertyExpr() {
115: return (propertyExpr);
116: }
117:
118: /**
119: * Getter method for "style" tag attribute. (Mapping set in associated
120: * BeanInfo class.)
121: */
122: public String getStyleExpr() {
123: return (styleExpr);
124: }
125:
126: /**
127: * Getter method for "styleClass" tag attribute. (Mapping set in
128: * associated BeanInfo class.)
129: */
130: public String getStyleClassExpr() {
131: return (styleClassExpr);
132: }
133:
134: /**
135: * Getter method for "value" tag attribute. (Mapping set in associated
136: * BeanInfo class.)
137: */
138: public String getValueExpr() {
139: return (valueExpr);
140: }
141:
142: /**
143: * Setter method for "filter" tag attribute. (Mapping set in associated
144: * BeanInfo class.)
145: */
146: public void setFilterExpr(String filterExpr) {
147: this .filterExpr = filterExpr;
148: }
149:
150: /**
151: * Setter method for "label" tag attribute. (Mapping set in associated
152: * BeanInfo class.)
153: */
154: public void setLabelExpr(String labelExpr) {
155: this .labelExpr = labelExpr;
156: }
157:
158: /**
159: * Setter method for "name" tag attribute. (Mapping set in associated
160: * BeanInfo class.)
161: */
162: public void setNameExpr(String nameExpr) {
163: this .nameExpr = nameExpr;
164: }
165:
166: /**
167: * Setter method for "property" tag attribute. (Mapping set in associated
168: * BeanInfo class.)
169: */
170: public void setPropertyExpr(String propertyExpr) {
171: this .propertyExpr = propertyExpr;
172: }
173:
174: /**
175: * Setter method for "style" tag attribute. (Mapping set in associated
176: * BeanInfo class.)
177: */
178: public void setStyleExpr(String styleExpr) {
179: this .styleExpr = styleExpr;
180: }
181:
182: /**
183: * Setter method for "styleClass" tag attribute. (Mapping set in
184: * associated BeanInfo class.)
185: */
186: public void setStyleClassExpr(String styleClassExpr) {
187: this .styleClassExpr = styleClassExpr;
188: }
189:
190: /**
191: * Setter method for "value" tag attribute. (Mapping set in associated
192: * BeanInfo class.)
193: */
194: public void setValueExpr(String valueExpr) {
195: this .valueExpr = valueExpr;
196: }
197:
198: /**
199: * Resets attribute values for tag reuse.
200: */
201: public void release() {
202: super .release();
203: setFilterExpr(null);
204: setLabelExpr(null);
205: setNameExpr(null);
206: setPropertyExpr(null);
207: setStyleExpr(null);
208: setStyleClassExpr(null);
209: setValueExpr(null);
210: }
211:
212: /**
213: * Process the start tag.
214: *
215: * @throws JspException if a JSP exception has occurred
216: */
217: public int doStartTag() throws JspException {
218: evaluateExpressions();
219:
220: return (super .doStartTag());
221: }
222:
223: /**
224: * Processes all attribute values which use the JSTL expression evaluation
225: * engine to determine their values.
226: *
227: * @throws JspException if a JSP exception has occurred
228: */
229: private void evaluateExpressions() throws JspException {
230: String string = null;
231: Boolean bool = null;
232:
233: if ((bool = EvalHelper.evalBoolean("filter", getFilterExpr(),
234: this , pageContext)) != null) {
235: setFilter(bool.booleanValue());
236: }
237:
238: if ((string = EvalHelper.evalString("label", getLabelExpr(),
239: this , pageContext)) != null) {
240: setLabel(string);
241: }
242:
243: if ((string = EvalHelper.evalString("name", getNameExpr(),
244: this , pageContext)) != null) {
245: setName(string);
246: }
247:
248: if ((string = EvalHelper.evalString("property",
249: getPropertyExpr(), this , pageContext)) != null) {
250: setProperty(string);
251: }
252:
253: if ((string = EvalHelper.evalString("style", getStyleExpr(),
254: this , pageContext)) != null) {
255: setStyle(string);
256: }
257:
258: if ((string = EvalHelper.evalString("styleClass",
259: getStyleClassExpr(), this , pageContext)) != null) {
260: setStyleClass(string);
261: }
262:
263: // Note that in contrast to other elements which have "style" and
264: // "styleClass" attributes, this tag does not have a "styleId"
265: // attribute. This is because this produces the "id" attribute, which
266: // has to be unique document-wide, but this tag can generate more than
267: // one "option" element. Thus, the base tag, "OptionsCollectionTag"
268: // does not support this attribute.
269: if ((string = EvalHelper.evalString("value", getValueExpr(),
270: this, pageContext)) != null) {
271: setValue(string);
272: }
273: }
274: }
|