View Javadoc

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