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