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