View Javadoc

1   /*
2    * $Id: ELOptionTag.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.OptionTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Tag for select options.  The body of this tag is presented to the user in
27   * the option list, while the value attribute is the value returned to the
28   * server if this option is selected. <p> This class is a subclass of the
29   * class <code>org.apache.struts.taglib.html.OptionTag</code> which provides
30   * most of the described functionality.  This subclass allows all attribute
31   * values to be specified as expressions utilizing the JavaServer Pages
32   * Standard Library expression language.
33   *
34   * @version $Rev: 376779 $
35   */
36  public class ELOptionTag extends OptionTag {
37      /***
38       * Instance variable mapped to "bundle" tag attribute. (Mapping set in
39       * associated BeanInfo class.)
40       */
41      private String bundleExpr;
42  
43      /***
44       * Instance variable mapped to "disabled" tag attribute. (Mapping set in
45       * associated BeanInfo class.)
46       */
47      private String disabledExpr;
48  
49      /***
50       * Instance variable mapped to "key" tag attribute. (Mapping set in
51       * associated BeanInfo class.)
52       */
53      private String keyExpr;
54  
55      /***
56       * Instance variable mapped to "locale" tag attribute. (Mapping set in
57       * associated BeanInfo class.)
58       */
59      private String localeExpr;
60  
61      /***
62       * Instance variable mapped to "style" tag attribute. (Mapping set in
63       * associated BeanInfo class.)
64       */
65      private String styleExpr;
66  
67      /***
68       * Instance variable mapped to "styleClass" tag attribute. (Mapping set in
69       * associated BeanInfo class.)
70       */
71      private String styleClassExpr;
72  
73      /***
74       * Instance variable mapped to "styleId" tag attribute. (Mapping set in
75       * associated BeanInfo class.)
76       */
77      private String styleIdExpr;
78  
79      /***
80       * Instance variable mapped to "value" tag attribute. (Mapping set in
81       * associated BeanInfo class.)
82       */
83      private String valueExpr;
84  
85      /***
86       * Getter method for "bundle" tag attribute. (Mapping set in associated
87       * BeanInfo class.)
88       */
89      public String getBundleExpr() {
90          return (bundleExpr);
91      }
92  
93      /***
94       * Getter method for "disabled" tag attribute. (Mapping set in associated
95       * BeanInfo class.)
96       */
97      public String getDisabledExpr() {
98          return (disabledExpr);
99      }
100 
101     /***
102      * Getter method for "key" tag attribute. (Mapping set in associated
103      * BeanInfo class.)
104      */
105     public String getKeyExpr() {
106         return (keyExpr);
107     }
108 
109     /***
110      * Getter method for "locale" tag attribute. (Mapping set in associated
111      * BeanInfo class.)
112      */
113     public String getLocaleExpr() {
114         return (localeExpr);
115     }
116 
117     /***
118      * Getter method for "style" tag attribute. (Mapping set in associated
119      * BeanInfo class.)
120      */
121     public String getStyleExpr() {
122         return (styleExpr);
123     }
124 
125     /***
126      * Getter method for "styleClass" tag attribute. (Mapping set in
127      * associated BeanInfo class.)
128      */
129     public String getStyleClassExpr() {
130         return (styleClassExpr);
131     }
132 
133     /***
134      * Getter method for "styleId" tag attribute. (Mapping set in associated
135      * BeanInfo class.)
136      */
137     public String getStyleIdExpr() {
138         return (styleIdExpr);
139     }
140 
141     /***
142      * Getter method for "value" tag attribute. (Mapping set in associated
143      * BeanInfo class.)
144      */
145     public String getValueExpr() {
146         return (valueExpr);
147     }
148 
149     /***
150      * Setter method for "bundle" tag attribute. (Mapping set in associated
151      * BeanInfo class.)
152      */
153     public void setBundleExpr(String bundleExpr) {
154         this.bundleExpr = bundleExpr;
155     }
156 
157     /***
158      * Setter method for "disabled" tag attribute. (Mapping set in associated
159      * BeanInfo class.)
160      */
161     public void setDisabledExpr(String disabledExpr) {
162         this.disabledExpr = disabledExpr;
163     }
164 
165     /***
166      * Setter method for "key" tag attribute. (Mapping set in associated
167      * BeanInfo class.)
168      */
169     public void setKeyExpr(String keyExpr) {
170         this.keyExpr = keyExpr;
171     }
172 
173     /***
174      * Setter method for "locale" tag attribute. (Mapping set in associated
175      * BeanInfo class.)
176      */
177     public void setLocaleExpr(String localeExpr) {
178         this.localeExpr = localeExpr;
179     }
180 
181     /***
182      * Setter method for "style" tag attribute. (Mapping set in associated
183      * BeanInfo class.)
184      */
185     public void setStyleExpr(String styleExpr) {
186         this.styleExpr = styleExpr;
187     }
188 
189     /***
190      * Setter method for "styleClass" tag attribute. (Mapping set in
191      * associated BeanInfo class.)
192      */
193     public void setStyleClassExpr(String styleClassExpr) {
194         this.styleClassExpr = styleClassExpr;
195     }
196 
197     /***
198      * Setter method for "styleId" tag attribute. (Mapping set in associated
199      * BeanInfo class.)
200      */
201     public void setStyleIdExpr(String styleIdExpr) {
202         this.styleIdExpr = styleIdExpr;
203     }
204 
205     /***
206      * Setter method for "value" tag attribute. (Mapping set in associated
207      * BeanInfo class.)
208      */
209     public void setValueExpr(String valueExpr) {
210         this.valueExpr = valueExpr;
211     }
212 
213     /***
214      * Resets attribute values for tag reuse.
215      */
216     public void release() {
217         super.release();
218         setBundleExpr(null);
219         setDisabledExpr(null);
220         setKeyExpr(null);
221         setLocaleExpr(null);
222         setStyleExpr(null);
223         setStyleClassExpr(null);
224         setStyleIdExpr(null);
225         setValueExpr(null);
226     }
227 
228     /***
229      * Process the start tag.
230      *
231      * @throws JspException if a JSP exception has occurred
232      */
233     public int doStartTag() throws JspException {
234         evaluateExpressions();
235 
236         return (super.doStartTag());
237     }
238 
239     /***
240      * Processes all attribute values which use the JSTL expression evaluation
241      * engine to determine their values.
242      *
243      * @throws JspException if a JSP exception has occurred
244      */
245     private void evaluateExpressions()
246         throws JspException {
247         String string = null;
248         Boolean bool = null;
249 
250         if ((string =
251                 EvalHelper.evalString("bundle", getBundleExpr(), this,
252                     pageContext)) != null) {
253             setBundle(string);
254         }
255 
256         if ((bool =
257                 EvalHelper.evalBoolean("disabled", getDisabledExpr(), this,
258                     pageContext)) != null) {
259             setDisabled(bool.booleanValue());
260         }
261 
262         if ((string =
263                 EvalHelper.evalString("key", getKeyExpr(), this, pageContext)) != null) {
264             setKey(string);
265         }
266 
267         if ((string =
268                 EvalHelper.evalString("locale", getLocaleExpr(), this,
269                     pageContext)) != null) {
270             setLocale(string);
271         }
272 
273         if ((string =
274                 EvalHelper.evalString("style", getStyleExpr(), this, pageContext)) != null) {
275             setStyle(string);
276         }
277 
278         if ((string =
279                 EvalHelper.evalString("styleClass", getStyleClassExpr(), this,
280                     pageContext)) != null) {
281             setStyleClass(string);
282         }
283 
284         if ((string =
285                 EvalHelper.evalString("styleId", getStyleIdExpr(), this,
286                     pageContext)) != null) {
287             setStyleId(string);
288         }
289 
290         if ((string =
291                 EvalHelper.evalString("value", getValueExpr(), this, pageContext)) != null) {
292             setValue(string);
293         }
294     }
295 }