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