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