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