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.component.Attributes;
28  import org.apache.myfaces.tobago.component.Facets;
29  import org.apache.myfaces.tobago.internal.component.AbstractUICommandBase;
30  import org.apache.myfaces.tobago.internal.taglib.MenuCommandTag;
31  import org.apache.myfaces.tobago.internal.taglib.SelectOneRadioTag;
32  import org.apache.myfaces.tobago.internal.util.StringUtils;
33  
34  import javax.faces.component.UIComponent;
35  import javax.faces.webapp.FacetTag;
36  import javax.servlet.jsp.JspException;
37  
38  /**
39   * Renders menu items like radio buttons (select one).
40   * <pre>
41   * &lt;tx:menuRadio>
42   *   &lt;tc:selectItems/> &lt;!-- body -->
43   * &lt;/tx:menuRadio></pre>
44   * is the short form of
45   * <pre>
46   * &lt;tc:menuCommand>
47   *   &lt;f:facet name="radio">
48   *     &lt;tc:selectOneRadio>
49   *       &lt;tc:selectItems/> &lt;!-- body -->
50   *     &lt;/tc:selectOneRadio>
51   *   &lt;/f:facet>
52   * &lt;/tc:menuCommand></pre>
53   */
54  @Tag(
55      name = "menuRadio",
56      tagExtraInfoClassName = "org.apache.myfaces.tobago.internal.taglib.component.CommandTagExtraInfo")
57  @ExtensionTag(
58      baseClassName = "org.apache.myfaces.tobago.internal.taglib.MenuRadioTag",
59      componentType = "org.apache.myfaces.tobago.MenuCommand",
60      rendererType = "MenuCommand",
61      faceletHandler = "org.apache.myfaces.tobago.facelets.extension.MenuRadioExtensionHandler")
62  public class MenuRadioExtensionTag extends TobagoExtensionBodyTagSupport {
63  
64    private javax.el.ValueExpression rendered;
65    private javax.el.ValueExpression value;
66  
67    private MenuCommandTag menuCommandTag;
68    private SelectOneRadioTag inTag;
69    private FacetTag facetTag;
70    private javax.el.MethodExpression action;
71    private javax.el.MethodExpression actionListener;
72    private javax.el.ValueExpression onclick;
73    private javax.el.ValueExpression link;
74    private javax.el.ValueExpression disabled;
75    private javax.el.ValueExpression binding;
76    private javax.el.ValueExpression label;
77    private javax.el.ValueExpression immediate;
78    private javax.el.ValueExpression transition;
79    private javax.el.ValueExpression converter;
80    private javax.el.ValueExpression renderedPartially;
81    private String fieldId;
82  
83    @Override
84    public int doStartTag() throws JspException {
85  
86      menuCommandTag = new MenuCommandTag();
87      menuCommandTag.setPageContext(pageContext);
88      menuCommandTag.setParent(getParent());
89      if (id != null) {
90        menuCommandTag.setId(id);
91      }
92      if (rendered != null) {
93        menuCommandTag.setRendered(rendered);
94      }
95      if (action != null) {
96        menuCommandTag.setAction(action);
97      }
98      if (actionListener != null) {
99        menuCommandTag.setActionListener(actionListener);
100     }
101     if (onclick != null) {
102       menuCommandTag.setOnclick(onclick);
103     }
104     if (link != null) {
105       menuCommandTag.setLink(link);
106     }
107     if (disabled != null) {
108       menuCommandTag.setDisabled(disabled);
109     }
110     if (binding != null) {
111       menuCommandTag.setBinding(binding);
112     }
113     if (label != null) {
114       menuCommandTag.setLabel(label);
115     }
116     if (immediate != null) {
117       menuCommandTag.setImmediate(immediate);
118     }
119     if (transition != null) {
120       menuCommandTag.setTransition(transition);
121     }
122     if (renderedPartially != null) {
123       menuCommandTag.setRenderedPartially(renderedPartially);
124     }
125     menuCommandTag.setJspId(nextJspId());
126     menuCommandTag.doStartTag();
127 
128     facetTag = new FacetTag();
129     facetTag.setPageContext(pageContext);
130     facetTag.setParent(menuCommandTag);
131     facetTag.setName(Facets.RADIO);
132 
133     facetTag.doStartTag();
134     inTag = new SelectOneRadioTag();
135     inTag.setPageContext(pageContext);
136     inTag.setParent(facetTag);
137     if (converter != null) {
138       inTag.setConverter(converter);
139     }
140     if (value != null) {
141       inTag.setValue(value);
142     }
143     if (fieldId != null) {
144       inTag.setId(fieldId);
145     }
146     inTag.setJspId(nextJspId());
147     inTag.doStartTag();
148 
149     return super.doStartTag();
150   }
151 
152   @Override
153   public int doEndTag() throws JspException {
154 
155     if (renderedPartially == null) {
156       // Move attribute renderedPartially from selectOne to menuCommand component
157       UIComponent inComponent = inTag.getComponentInstance();
158       AbstractUICommandBase command = (AbstractUICommandBase) menuCommandTag.getComponentInstance();
159       javax.el.ValueExpression expression = inComponent.getValueExpression(Attributes.RENDERED_PARTIALLY);
160       if (expression != null) {
161         command.setValueExpression(Attributes.RENDERED_PARTIALLY, expression);
162       } else {
163         Object renderedPartially = inComponent.getAttributes().get(Attributes.RENDERED_PARTIALLY);
164         command.setRenderedPartially(StringUtils.split((String) renderedPartially, ", "));
165       }
166     }
167 
168     inTag.doEndTag();
169     facetTag.doEndTag();
170     menuCommandTag.doEndTag();
171 
172     return super.doEndTag();
173   }
174 
175   public void release() {
176     super.release();
177     rendered = null;
178     value = null;
179     action = null;
180     actionListener = null;
181     onclick = null;
182     link = null;
183     disabled = null;
184     binding = null;
185     label = null;
186     immediate = null;
187     transition = null;
188     converter = null;
189     renderedPartially = null;
190     fieldId = null;
191     menuCommandTag = null;
192     facetTag = null;
193     inTag = null;
194   }
195 
196   /**
197    * Action to invoke when clicked.
198    * This must be a MethodBinding or a String representing the application action to invoke when
199    * this component is activated by the user.
200    * The MethodBinding must evaluate to a public method that takes no parameters,
201    * and returns a String (the logical outcome) which is passed to the
202    * NavigationHandler for this application.
203    * The String is directly passed to the Navigationhandler.
204    */
205   @TagAttribute
206   @UIComponentTagAttribute(type = {}, expression = DynamicExpression.METHOD_EXPRESSION,
207       methodReturnType = "java.lang.Object")
208   public void setAction(javax.el.MethodExpression action) {
209     this.action = action;
210   }
211 
212   /**
213    * MethodBinding representing an action listener method that will be
214    * notified when this component is activated by the user.
215    * The expression must evaluate to a public method that takes an ActionEvent
216    * parameter, with a return type of void.
217    */
218   @TagAttribute
219   @UIComponentTagAttribute(type = {}, expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
220       methodSignature = "javax.faces.event.ActionEvent")
221   public void setActionListener(javax.el.MethodExpression actionListener) {
222     this.actionListener = actionListener;
223   }
224 
225   /**
226    * Script to be invoked when clicked
227    */
228   @TagAttribute
229   @UIComponentTagAttribute()
230   public void setOnclick(javax.el.ValueExpression onclick) {
231     this.onclick = onclick;
232   }
233 
234   /**
235    * Link to an arbitrary URL
236    */
237   @TagAttribute
238   @UIComponentTagAttribute()
239   public void setLink(javax.el.ValueExpression link) {
240     this.link = link;
241   }
242 
243   /**
244    * The value binding expression linking this
245    * component to a property in a backing bean.
246    */
247   @TagAttribute
248   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
249   public void setBinding(javax.el.ValueExpression binding) throws JspException {
250     this.binding = binding;
251   }
252 
253   /**
254    * Flag indicating whether or not this component should be rendered
255    * (during Render Response Phase), or processed on any subsequent form submit.
256    */
257   @TagAttribute
258   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
259   public void setRendered(javax.el.ValueExpression rendered) {
260     this.rendered = rendered;
261   }
262 
263   /**
264    * Flag indicating that this element is disabled.
265    */
266   @TagAttribute()
267   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
268   public void setDisabled(javax.el.ValueExpression disabled) {
269     this.disabled = disabled;
270   }
271 
272   /**
273    * The current value of this component.
274    */
275   @TagAttribute
276   @UIComponentTagAttribute(type = "java.lang.Object")
277   public void setValue(javax.el.ValueExpression value) {
278     this.value = value;
279   }
280 
281   /**
282    * Text value to display as label.
283    * If text contains an underscore the next character is used as accesskey.
284    */
285   @TagAttribute
286   @UIComponentTagAttribute()
287   public void setLabel(javax.el.ValueExpression label) {
288     this.label = label;
289   }
290 
291   /**
292    * Flag indicating that, if this component is activated by the user,
293    * notifications should be delivered to interested listeners and actions
294    * immediately (that is, during Apply Request Values phase) rather than
295    * waiting until Invoke Application phase.
296    */
297   @TagAttribute
298   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
299   public void setImmediate(javax.el.ValueExpression immediate) {
300     this.immediate = immediate;
301   }
302 
303   /**
304    * Specify, if the command calls an JSF-Action.
305    * Useful to switch off the Double-Submit-Check and Waiting-Behavior.
306    *
307    * @param transition Indicates the transition.
308    */
309   @TagAttribute
310   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
311   public void setTransition(javax.el.ValueExpression transition) {
312     this.transition = transition;
313   }
314 
315   /**
316    * An expression that specifies the Converter for this component.
317    * If the value binding expression is a String,
318    * the String is used as an ID to look up a Converter.
319    * If the value binding expression is a Converter,
320    * uses that instance as the converter.
321    * The value can either be a static value (ID case only)
322    * or an EL expression.
323    */
324   @TagAttribute
325   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
326       expression = DynamicExpression.VALUE_EXPRESSION)
327   public void setConverter(javax.el.ValueExpression converter) {
328     this.converter = converter;
329   }
330 
331   /**
332    * Indicate the partially rendered Components in a case of a submit.
333    */
334    @TagAttribute
335    @UIComponentTagAttribute(type = "java.lang.String[]")
336   public void setRenderedPartially(javax.el.ValueExpression renderedPartially) {
337     this.renderedPartially = renderedPartially;
338   }
339 
340   /**
341    * The component identifier for the input field component inside of the container.
342    * This value must be unique within the closest parent component that is a naming container.
343    */
344   @TagAttribute(rtexprvalue = true)
345   @UIComponentTagAttribute
346   public void setFieldId(String fieldId) {
347     this.fieldId = fieldId;
348   }
349 
350   /**
351    * The component identifier for this component.
352    * This value must be unique within the closest parent component that is a naming container.
353    * For tx components the id will be set to the container (e. g. the panel).
354    * To set the id of the input field, you have to use the attribute "fieldId".
355    */
356   @TagAttribute(rtexprvalue = true)
357   @UIComponentTagAttribute
358   public void setId(String id) {
359     super.setId(id);
360   }
361 }