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