KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > html > ELOptionsCollectionTag


1 /*
2  * $Id: ELOptionsCollectionTag.java 54933 2004-10-16 17:04:52Z germuska $
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
19 package org.apache.strutsel.taglib.html;
20
21 import org.apache.struts.taglib.html.OptionsCollectionTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import org.apache.strutsel.taglib.utils.EvalHelper;
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
28  * the form. Each element of the collection must expose a 'label' and a
29  * 'value', the property names of which are configurable by attributes of
30  * this tag.
31  * <p>
32  * The collection may be an array of objects, a Collection, an Enumeration,
33  * an Iterator, or a Map.
34  * <p>
35  * <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or later) platform.
36  *<p>
37  * This class is a subclass of the class
38  * <code>org.apache.struts.taglib.html.OptionsCollectionTag</code> which
39  * provides most of the described functionality. This subclass allows all
40  * attribute values to be specified as expressions utilizing the JavaServer
41  * Pages Standard Library expression language.
42  *
43  * @version $Rev: 54933 $
44  */

45 public class ELOptionsCollectionTag extends OptionsCollectionTag {
46
47     /**
48      * Instance variable mapped to "filter" tag attribute.
49      * (Mapping set in associated BeanInfo class.)
50      */

51     private String JavaDoc filterExpr;
52     /**
53      * Instance variable mapped to "label" tag attribute.
54      * (Mapping set in associated BeanInfo class.)
55      */

56     private String JavaDoc labelExpr;
57     /**
58      * Instance variable mapped to "name" tag attribute.
59      * (Mapping set in associated BeanInfo class.)
60      */

61     private String JavaDoc nameExpr;
62     /**
63      * Instance variable mapped to "property" tag attribute.
64      * (Mapping set in associated BeanInfo class.)
65      */

66     private String JavaDoc propertyExpr;
67     /**
68      * Instance variable mapped to "style" tag attribute.
69      * (Mapping set in associated BeanInfo class.)
70      */

71     private String JavaDoc styleExpr;
72     /**
73      * Instance variable mapped to "styleClass" tag attribute.
74      * (Mapping set in associated BeanInfo class.)
75      */

76     private String JavaDoc styleClassExpr;
77     /**
78      * Instance variable mapped to "value" tag attribute.
79      * (Mapping set in associated BeanInfo class.)
80      */

81     private String JavaDoc valueExpr;
82
83     /**
84      * Getter method for "filter" tag attribute.
85      * (Mapping set in associated BeanInfo class.)
86      */

87     public String JavaDoc getFilterExpr() { return (filterExpr); }
88     /**
89      * Getter method for "label" tag attribute.
90      * (Mapping set in associated BeanInfo class.)
91      */

92     public String JavaDoc getLabelExpr() { return (labelExpr); }
93     /**
94      * Getter method for "name" tag attribute.
95      * (Mapping set in associated BeanInfo class.)
96      */

97     public String JavaDoc getNameExpr() { return (nameExpr); }
98     /**
99      * Getter method for "property" tag attribute.
100      * (Mapping set in associated BeanInfo class.)
101      */

102     public String JavaDoc getPropertyExpr() { return (propertyExpr); }
103     /**
104      * Getter method for "style" tag attribute.
105      * (Mapping set in associated BeanInfo class.)
106      */

107     public String JavaDoc getStyleExpr() { return (styleExpr); }
108     /**
109      * Getter method for "styleClass" tag attribute.
110      * (Mapping set in associated BeanInfo class.)
111      */

112     public String JavaDoc getStyleClassExpr() { return (styleClassExpr); }
113     /**
114      * Getter method for "value" tag attribute.
115      * (Mapping set in associated BeanInfo class.)
116      */

117     public String JavaDoc getValueExpr() { return (valueExpr); }
118
119     /**
120      * Setter method for "filter" tag attribute.
121      * (Mapping set in associated BeanInfo class.)
122      */

123     public void setFilterExpr(String JavaDoc filterExpr) { this.filterExpr = filterExpr; }
124     /**
125      * Setter method for "label" tag attribute.
126      * (Mapping set in associated BeanInfo class.)
127      */

128     public void setLabelExpr(String JavaDoc labelExpr) { this.labelExpr = labelExpr; }
129     /**
130      * Setter method for "name" tag attribute.
131      * (Mapping set in associated BeanInfo class.)
132      */

133     public void setNameExpr(String JavaDoc nameExpr) { this.nameExpr = nameExpr; }
134     /**
135      * Setter method for "property" tag attribute.
136      * (Mapping set in associated BeanInfo class.)
137      */

138     public void setPropertyExpr(String JavaDoc propertyExpr) { this.propertyExpr = propertyExpr; }
139     /**
140      * Setter method for "style" tag attribute.
141      * (Mapping set in associated BeanInfo class.)
142      */

143     public void setStyleExpr(String JavaDoc styleExpr) { this.styleExpr = styleExpr; }
144     /**
145      * Setter method for "styleClass" tag attribute.
146      * (Mapping set in associated BeanInfo class.)
147      */

148     public void setStyleClassExpr(String JavaDoc styleClassExpr) { this.styleClassExpr = styleClassExpr; }
149     /**
150      * Setter method for "value" tag attribute.
151      * (Mapping set in associated BeanInfo class.)
152      */

153     public void setValueExpr(String JavaDoc valueExpr) { this.valueExpr = valueExpr; }
154
155     /**
156      * Resets attribute values for tag reuse.
157      */

158     public void release()
159     {
160         super.release();
161         setFilterExpr(null);
162         setLabelExpr(null);
163         setNameExpr(null);
164         setPropertyExpr(null);
165         setStyleExpr(null);
166         setStyleClassExpr(null);
167         setValueExpr(null);
168     }
169
170     /**
171      * Process the start tag.
172      *
173      * @exception JspException if a JSP exception has occurred
174      */

175     public int doStartTag() throws JspException JavaDoc {
176         evaluateExpressions();
177         return (super.doStartTag());
178     }
179     
180     /**
181      * Processes all attribute values which use the JSTL expression evaluation
182      * engine to determine their values.
183      *
184      * @exception JspException if a JSP exception has occurred
185      */

186     private void evaluateExpressions() throws JspException JavaDoc {
187         String JavaDoc string = null;
188         Boolean JavaDoc bool = null;
189
190         if ((bool = EvalHelper.evalBoolean("filter", getFilterExpr(),
191                                            this, pageContext)) != null)
192             setFilter(bool.booleanValue());
193
194         if ((string = EvalHelper.evalString("label", getLabelExpr(),
195                                             this, pageContext)) != null)
196             setLabel(string);
197
198         if ((string = EvalHelper.evalString("name", getNameExpr(),
199                                             this, pageContext)) != null)
200             setName(string);
201
202         if ((string = EvalHelper.evalString("property", getPropertyExpr(),
203                                             this, pageContext)) != null)
204             setProperty(string);
205
206         if ((string = EvalHelper.evalString("style", getStyleExpr(),
207                                             this, pageContext)) != null)
208             setStyle(string);
209
210         if ((string = EvalHelper.evalString("styleClass", getStyleClassExpr(),
211                                             this, pageContext)) != null)
212             setStyleClass(string);
213
214         // Note that in contrast to other elements which have "style" and
215
// "styleClass" attributes, this tag does not have a "styleId"
216
// attribute. This is because this produces the "id" attribute, which
217
// has to be unique document-wide, but this tag can generate more than
218
// one "option" element. Thus, the base tag, "OptionsCollectionTag"
219
// does not support this attribute.
220

221         if ((string = EvalHelper.evalString("value", getValueExpr(),
222                                             this, pageContext)) != null)
223             setValue(string);
224     }
225 }
226
Popular Tags