View Javadoc

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