View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.taglib.extension;
21  
22  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
23  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
24  import org.apache.myfaces.tobago.apt.annotation.Tag;
25  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
26  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
27  import org.apache.myfaces.tobago.internal.taglib.SelectOneListboxTag;
28  
29  import javax.el.MethodExpression;
30  import javax.el.ValueExpression;
31  import javax.servlet.jsp.JspException;
32  
33  /**
34   * Render a single selection option listbox.
35   */
36  @Tag(name = "selectOneListbox")
37  @ExtensionTag(
38      baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectOneListboxTag",
39      faceletHandler = "org.apache.myfaces.tobago.facelets.extension.SelectOneListboxExtensionHandler")
40  public class SelectOneListboxExtensionTag extends TobagoExtensionBodyTagSupport {
41    private ValueExpression required;
42    private ValueExpression value;
43    private MethodExpression valueChangeListener;
44    private ValueExpression disabled;
45    private ValueExpression readonly;
46    private ValueExpression onchange;
47    //private javax.el.ValueExpression inline;
48    private ValueExpression label;
49    private ValueExpression accessKey;
50    private ValueExpression rendered;
51    private ValueExpression binding;
52    private ValueExpression tip;
53    private ValueExpression converter;
54    private MethodExpression validator;
55    private ValueExpression labelWidth;
56    private ValueExpression tabIndex;
57    private ValueExpression focus;
58    private ValueExpression validatorMessage;
59    private ValueExpression converterMessage;
60    private ValueExpression requiredMessage;
61    private ValueExpression markup;
62    private String fieldId;
63  
64    private LabelExtensionTag labelTag;
65    private SelectOneListboxTag selectOneListboxTag;
66  
67    @Override
68    public int doStartTag() throws JspException {
69  
70      labelTag = new LabelExtensionTag();
71      labelTag.setPageContext(pageContext);
72      labelTag.setRows("*");
73      if (id != null) {
74        labelTag.setId(id);
75      }
76      if (label != null) {
77        labelTag.setValue(label);
78      }
79      if (accessKey != null) {
80        labelTag.setAccessKey(accessKey);
81      }
82      if (tip != null) {
83        labelTag.setTip(tip);
84      }
85      if (rendered != null) {
86        labelTag.setRendered(rendered);
87      }
88      if (labelWidth != null) {
89        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
90      }
91      if (markup != null) {
92        labelTag.setMarkup(markup);
93      }
94      labelTag.setParent(getParent());
95      labelTag.setJspId(nextJspId());
96      labelTag.doStartTag();
97  
98      selectOneListboxTag = new SelectOneListboxTag();
99      selectOneListboxTag.setPageContext(pageContext);
100     if (value != null) {
101       selectOneListboxTag.setValue(value);
102     }
103     if (valueChangeListener != null) {
104       selectOneListboxTag.setValueChangeListener(valueChangeListener);
105     }
106     if (binding != null) {
107       selectOneListboxTag.setBinding(binding);
108     }
109     if (onchange != null) {
110       selectOneListboxTag.setOnchange(onchange);
111     }
112     if (validator != null) {
113       selectOneListboxTag.setValidator(validator);
114     }
115     if (converter != null) {
116       selectOneListboxTag.setConverter(converter);
117     }
118     if (disabled != null) {
119       selectOneListboxTag.setDisabled(disabled);
120     }
121     /*if (inline != null) {
122       selectOneListboxTag.setInline(inline);
123     }*/
124     if (focus != null) {
125       selectOneListboxTag.setFocus(focus);
126     }
127     if (fieldId != null) {
128       selectOneListboxTag.setId(fieldId);
129     }
130     if (label != null) {
131       selectOneListboxTag.setLabel(label);
132     }
133     if (readonly != null) {
134       selectOneListboxTag.setReadonly(readonly);
135     }
136     if (required != null) {
137       selectOneListboxTag.setRequired(required);
138     }
139     if (tabIndex != null) {
140       selectOneListboxTag.setTabIndex(tabIndex);
141     }
142     if (validatorMessage != null) {
143       selectOneListboxTag.setValidatorMessage(validatorMessage);
144     }
145     if (converterMessage != null) {
146       selectOneListboxTag.setConverterMessage(converterMessage);
147     }
148     if (requiredMessage != null) {
149       selectOneListboxTag.setRequiredMessage(requiredMessage);
150     }
151     if (markup != null) {
152       selectOneListboxTag.setMarkup(markup);
153     }
154     selectOneListboxTag.setParent(labelTag);
155     selectOneListboxTag.setJspId(nextJspId());
156     selectOneListboxTag.doStartTag();
157 
158     return super.doStartTag();
159   }
160 
161   @Override
162   public int doEndTag() throws JspException {
163     selectOneListboxTag.doEndTag();
164     labelTag.doEndTag();
165     return super.doEndTag();
166   }
167 
168   @Override
169   public void release() {
170     super.release();
171     binding = null;
172     onchange = null;
173     disabled = null;
174     //inline = null;
175     labelWidth = null;
176     label = null;
177     accessKey = null;
178     readonly = null;
179     rendered = null;
180     converter = null;
181     validator = null;
182     required = null;
183     tip = null;
184     value = null;
185     valueChangeListener = null;
186     tabIndex = null;
187     selectOneListboxTag = null;
188     labelTag = null;
189     focus = null;
190     validatorMessage = null;
191     converterMessage = null;
192     requiredMessage = null;
193     markup = null;
194     fieldId = null;
195   }
196 
197   /**
198    * Flag indicating that a value is required.
199    * If the value is an empty string a
200    * ValidationError occurs and a Error Message is rendered.
201    */
202   @TagAttribute
203   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
204   public void setRequired(final ValueExpression required) {
205     this.required = required;
206   }
207 
208   /**
209    * The current value of this component.
210    */
211   @TagAttribute
212   @UIComponentTagAttribute(type = "java.lang.Object")
213   public void setValue(final ValueExpression value) {
214     this.value = value;
215   }
216 
217   /**
218    * MethodBinding representing a value change listener method
219    * that will be notified when a new value has been set for this input component.
220    * The expression must evaluate to a public method that takes a ValueChangeEvent
221    * parameter, with a return type of void.
222    *
223    * @param valueChangeListener
224    */
225   @TagAttribute
226   @UIComponentTagAttribute(
227           type = {},
228           expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
229           methodSignature = "javax.faces.event.ValueChangeEvent")
230   public void setValueChangeListener(final MethodExpression valueChangeListener) {
231     this.valueChangeListener = valueChangeListener;
232   }
233 
234   /**
235    * Flag indicating that this element is disabled.
236    */
237   @TagAttribute()
238   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
239   public void setDisabled(final ValueExpression disabled) {
240     this.disabled = disabled;
241   }
242 
243   /**
244    * Flag indicating that this component will prohibit changes by the user.
245    */
246   @TagAttribute
247   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
248   public void setReadonly(final ValueExpression readonly) {
249     this.readonly = readonly;
250   }
251 
252   /**
253    * Clientside script function to add to this component's onchange handler.
254    */
255   @TagAttribute
256   @UIComponentTagAttribute()
257   public void setOnchange(final ValueExpression onchange) {
258     this.onchange = onchange;
259   }
260 
261   /**
262    * Text value to display as label.
263    * If text contains an underscore the next character is used as accesskey.
264    */
265   @TagAttribute
266   @UIComponentTagAttribute()
267   public void setLabel(final ValueExpression label) {
268     this.label = label;
269   }
270 
271   /**
272    * The accessKey of this component.
273    */
274   @TagAttribute
275   @UIComponentTagAttribute(type = "java.lang.Character")
276   public void setAccessKey(final javax.el.ValueExpression accessKey) {
277     this.accessKey = accessKey;
278   }
279 
280   /**
281    * A method binding EL expression,
282    * accepting FacesContext, UIComponent,
283    * and Object parameters, and returning void, that validates
284    * the component's local value.
285    */
286   @TagAttribute
287   @UIComponentTagAttribute(type = {},
288       expression = DynamicExpression.METHOD_EXPRESSION,
289       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
290   public void setValidator(final MethodExpression validator) {
291     this.validator = validator;
292   }
293 
294   /**
295    * An expression that specifies the Converter for this component.
296    * If the value binding expression is a String,
297    * the String is used as an ID to look up a Converter.
298    * If the value binding expression is a Converter,
299    * uses that instance as the converter.
300    * The value can either be a static value (ID case only)
301    * or an EL expression.
302    */
303   @TagAttribute
304   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
305       expression = DynamicExpression.VALUE_EXPRESSION)
306   public void setConverter(final ValueExpression converter) {
307     this.converter = converter;
308   }
309 
310   /**
311    * Flag indicating whether or not this component should be rendered
312    * (during Render Response Phase), or processed on any subsequent form submit.
313    */
314   @TagAttribute
315   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
316   public void setRendered(final ValueExpression rendered) {
317     this.rendered = rendered;
318   }
319 
320   /**
321    * The value binding expression linking this
322    * component to a property in a backing bean.
323    */
324   @TagAttribute
325   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
326   public void setBinding(final ValueExpression binding) {
327     this.binding = binding;
328   }
329 
330   /**
331    * Text value to display as tooltip.
332    */
333   @TagAttribute
334   @UIComponentTagAttribute()
335   public void setTip(final ValueExpression tip) {
336     this.tip = tip;
337   }
338 
339   /**
340    * The width for the label component. Default: 'auto'.
341    * This value is used in the gridLayouts columns attribute.
342    * See gridLayout tag for valid values.
343    */
344   @TagAttribute
345   @UIComponentTagAttribute()
346   public void setLabelWidth(final ValueExpression labelWidth) {
347     this.labelWidth = labelWidth;
348   }
349 
350   @TagAttribute
351   @UIComponentTagAttribute(type = "java.lang.Integer")
352   public void setTabIndex(final ValueExpression tabIndex) {
353     this.tabIndex = tabIndex;
354   }
355 
356   /**
357    * Flag indicating this component should receive the focus.
358    */
359   @TagAttribute
360   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
361   public void setFocus(final ValueExpression focus) {
362     this.focus = focus;
363   }
364 
365   /**
366    * An expression that specifies the validator message
367    */
368   @TagAttribute
369   @UIComponentTagAttribute()
370   public void setValidatorMessage(final ValueExpression validatorMessage) {
371     this.validatorMessage = validatorMessage;
372   }
373 
374   /**
375    * An expression that specifies the converter message
376    */
377   @TagAttribute
378   @UIComponentTagAttribute()
379   public void setConverterMessage(final ValueExpression converterMessage) {
380     this.converterMessage = converterMessage;
381   }
382 
383   /**
384    * An expression that specifies the required message
385    */
386   @TagAttribute
387   @UIComponentTagAttribute()
388   public void setRequiredMessage(final ValueExpression requiredMessage) {
389     this.requiredMessage = requiredMessage;
390   }
391 
392   /**
393    * Indicate markup of this component.
394    * Possible value is 'none'. But this can be overridden in the theme.
395    */
396   @TagAttribute
397   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
398   public void setMarkup(final ValueExpression markup) {
399     this.markup = markup;
400   }
401 
402   /**
403    * The component identifier for the input field component inside of the container.
404    * This value must be unique within the closest parent component that is a naming container.
405    */
406   @TagAttribute(rtexprvalue = true)
407   @UIComponentTagAttribute
408   public void setFieldId(final String fieldId) {
409     this.fieldId = fieldId;
410   }
411 
412   /**
413    * The component identifier for this component.
414    * This value must be unique within the closest parent component that is a naming container.
415    * For tx components the id will be set to the container (e. g. the panel).
416    * To set the id of the input field, you have to use the attribute "fieldId".
417    */
418   @TagAttribute(rtexprvalue = true)
419   @UIComponentTagAttribute
420   public void setId(final String id) {
421     super.setId(id);
422   }
423 }