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