View Javadoc

1   /*
2    * $Id: ELOptionsTag.java 376779 2006-02-10 18:08:58Z husted $
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  package org.apache.strutsel.taglib.html;
19  
20  import org.apache.struts.taglib.html.OptionsTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Tag for creating multiple <select> options from a collection.  The
27   * associated values displayed to the user may optionally be specified by a
28   * second collection, or will be the same as the values themselves.  Each
29   * collection may be an array of objects, a Collection, an Enumeration, an
30   * Iterator, or a Map. <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or
31   * later) platform. <p> This class is a subclass of the class
32   * <code>org.apache.struts.taglib.html.OptionsTag</code> which provides most
33   * of the described functionality.  This subclass allows all attribute values
34   * to be specified as expressions utilizing the JavaServer Pages Standard
35   * Library expression language.
36   *
37   * @version $Rev: 376779 $
38   */
39  public class ELOptionsTag extends OptionsTag {
40      /***
41       * Instance variable mapped to "collection" tag attribute. (Mapping set in
42       * associated BeanInfo class.)
43       */
44      private String collectionExpr;
45  
46      /***
47       * Instance variable mapped to "filter" tag attribute. (Mapping set in
48       * associated BeanInfo class.)
49       */
50      private String filterExpr;
51  
52      /***
53       * Instance variable mapped to "labelName" tag attribute. (Mapping set in
54       * associated BeanInfo class.)
55       */
56      private String labelNameExpr;
57  
58      /***
59       * Instance variable mapped to "labelProperty" tag attribute. (Mapping set
60       * in associated BeanInfo class.)
61       */
62      private String labelPropertyExpr;
63  
64      /***
65       * Instance variable mapped to "name" tag attribute. (Mapping set in
66       * associated BeanInfo class.)
67       */
68      private String nameExpr;
69  
70      /***
71       * Instance variable mapped to "property" tag attribute. (Mapping set in
72       * associated BeanInfo class.)
73       */
74      private String propertyExpr;
75  
76      /***
77       * Instance variable mapped to "style" tag attribute. (Mapping set in
78       * associated BeanInfo class.)
79       */
80      private String styleExpr;
81  
82      /***
83       * Instance variable mapped to "styleClass" tag attribute. (Mapping set in
84       * associated BeanInfo class.)
85       */
86      private String styleClassExpr;
87  
88      /***
89       * Getter method for "collection" tag attribute. (Mapping set in
90       * associated BeanInfo class.)
91       */
92      public String getCollectionExpr() {
93          return (collectionExpr);
94      }
95  
96      /***
97       * Getter method for "filter" tag attribute. (Mapping set in associated
98       * BeanInfo class.)
99       */
100     public String getFilterExpr() {
101         return (filterExpr);
102     }
103 
104     /***
105      * Getter method for "labelName" tag attribute. (Mapping set in associated
106      * BeanInfo class.)
107      */
108     public String getLabelNameExpr() {
109         return (labelNameExpr);
110     }
111 
112     /***
113      * Getter method for "labelProperty" tag attribute. (Mapping set in
114      * associated BeanInfo class.)
115      */
116     public String getLabelPropertyExpr() {
117         return (labelPropertyExpr);
118     }
119 
120     /***
121      * Getter method for "name" tag attribute. (Mapping set in associated
122      * BeanInfo class.)
123      */
124     public String getNameExpr() {
125         return (nameExpr);
126     }
127 
128     /***
129      * Getter method for "property" tag attribute. (Mapping set in associated
130      * BeanInfo class.)
131      */
132     public String getPropertyExpr() {
133         return (propertyExpr);
134     }
135 
136     /***
137      * Getter method for "style" tag attribute. (Mapping set in associated
138      * BeanInfo class.)
139      */
140     public String getStyleExpr() {
141         return (styleExpr);
142     }
143 
144     /***
145      * Getter method for "styleClass" tag attribute. (Mapping set in
146      * associated BeanInfo class.)
147      */
148     public String getStyleClassExpr() {
149         return (styleClassExpr);
150     }
151 
152     /***
153      * Setter method for "collection" tag attribute. (Mapping set in
154      * associated BeanInfo class.)
155      */
156     public void setCollectionExpr(String collectionExpr) {
157         this.collectionExpr = collectionExpr;
158     }
159 
160     /***
161      * Setter method for "filter" tag attribute. (Mapping set in associated
162      * BeanInfo class.)
163      */
164     public void setFilterExpr(String filterExpr) {
165         this.filterExpr = filterExpr;
166     }
167 
168     /***
169      * Setter method for "labelName" tag attribute. (Mapping set in associated
170      * BeanInfo class.)
171      */
172     public void setLabelNameExpr(String labelNameExpr) {
173         this.labelNameExpr = labelNameExpr;
174     }
175 
176     /***
177      * Setter method for "labelProperty" tag attribute. (Mapping set in
178      * associated BeanInfo class.)
179      */
180     public void setLabelPropertyExpr(String labelPropertyExpr) {
181         this.labelPropertyExpr = labelPropertyExpr;
182     }
183 
184     /***
185      * Setter method for "name" tag attribute. (Mapping set in associated
186      * BeanInfo class.)
187      */
188     public void setNameExpr(String nameExpr) {
189         this.nameExpr = nameExpr;
190     }
191 
192     /***
193      * Setter method for "property" tag attribute. (Mapping set in associated
194      * BeanInfo class.)
195      */
196     public void setPropertyExpr(String propertyExpr) {
197         this.propertyExpr = propertyExpr;
198     }
199 
200     /***
201      * Setter method for "style" tag attribute. (Mapping set in associated
202      * BeanInfo class.)
203      */
204     public void setStyleExpr(String styleExpr) {
205         this.styleExpr = styleExpr;
206     }
207 
208     /***
209      * Setter method for "styleClass" tag attribute. (Mapping set in
210      * associated BeanInfo class.)
211      */
212     public void setStyleClassExpr(String styleClassExpr) {
213         this.styleClassExpr = styleClassExpr;
214     }
215 
216     /***
217      * Resets attribute values for tag reuse.
218      */
219     public void release() {
220         super.release();
221         setCollectionExpr(null);
222         setFilterExpr(null);
223         setLabelNameExpr(null);
224         setLabelPropertyExpr(null);
225         setNameExpr(null);
226         setPropertyExpr(null);
227         setStyleExpr(null);
228         setStyleClassExpr(null);
229     }
230 
231     /***
232      * Process the start tag.
233      *
234      * @throws JspException if a JSP exception has occurred
235      */
236     public int doStartTag() throws JspException {
237         evaluateExpressions();
238 
239         return (super.doStartTag());
240     }
241 
242     /***
243      * Processes all attribute values which use the JSTL expression evaluation
244      * engine to determine their values.
245      *
246      * @throws JspException if a JSP exception has occurred
247      */
248     private void evaluateExpressions()
249         throws JspException {
250         String string = null;
251         Boolean bool = null;
252 
253         if ((string =
254                 EvalHelper.evalString("collection", getCollectionExpr(), this,
255                     pageContext)) != null) {
256             setCollection(string);
257         }
258 
259         if ((bool =
260                 EvalHelper.evalBoolean("filter", getFilterExpr(), this,
261                     pageContext)) != null) {
262             setFilter(bool.booleanValue());
263         }
264 
265         if ((string =
266                 EvalHelper.evalString("labelName", getLabelNameExpr(), this,
267                     pageContext)) != null) {
268             setLabelName(string);
269         }
270 
271         if ((string =
272                 EvalHelper.evalString("labelProperty", getLabelPropertyExpr(),
273                     this, pageContext)) != null) {
274             setLabelProperty(string);
275         }
276 
277         if ((string =
278                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
279             setName(string);
280         }
281 
282         if ((string =
283                 EvalHelper.evalString("property", getPropertyExpr(), this,
284                     pageContext)) != null) {
285             setProperty(string);
286         }
287 
288         if ((string =
289                 EvalHelper.evalString("style", getStyleExpr(), this, pageContext)) != null) {
290             setStyle(string);
291         }
292 
293         if ((string =
294                 EvalHelper.evalString("styleClass", getStyleClassExpr(), this,
295                     pageContext)) != null) {
296             setStyleClass(string);
297         }
298 
299         // Note that in contrast to other elements which have "style" and
300         // "styleClass" attributes, this tag does not have a "styleId"
301         // attribute.  This is because this produces the "id" attribute, which
302         // has to be unique document-wide, but this tag can generate more than
303         // one "option" element.  Thus, the base tag, "Options" does not
304         // support this attribute.
305     }
306 }