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