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.commons.lang.StringUtils;
21  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
22  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
23  import org.apache.myfaces.tobago.apt.annotation.Tag;
24  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
25  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
26  import org.apache.myfaces.tobago.component.Attributes;
27  import org.apache.myfaces.tobago.component.Facets;
28  import org.apache.myfaces.tobago.component.UICommandBase;
29  import org.apache.myfaces.tobago.internal.taglib.MenuItemTag;
30  import org.apache.myfaces.tobago.internal.taglib.SelectOneRadioTag;
31  
32  import javax.faces.component.UIComponent;
33  import javax.faces.webapp.FacetTag;
34  import javax.servlet.jsp.JspException;
35  import javax.servlet.jsp.tagext.BodyTagSupport;
36  
37  /*
38   * Date: 09.05.2006
39   * Time: 17:41:39
40   */
41  
42  /**
43   * Renders a submenu with select one items (like a radio button).
44   */
45  
46  @Tag(name = "menuRadio", tagExtraInfoClassName = "org.apache.myfaces.tobago.taglib.component.CommandTagExtraInfo")
47  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.MenuRadioTag")
48  public class MenuRadioExtensionTag extends BodyTagSupport {
49  
50    private javax.el.ValueExpression rendered;
51    private javax.el.ValueExpression value;
52  
53    private MenuItemTag menuCommandTag;
54    private SelectOneRadioTag selectOneRadio;
55    private FacetTag facetTag;
56    private javax.el.MethodExpression action;
57    private javax.el.MethodExpression actionListener;
58    private javax.el.ValueExpression onclick;
59    private javax.el.ValueExpression link;
60    private javax.el.ValueExpression disabled;
61    private javax.el.ValueExpression binding;
62    private javax.el.ValueExpression label;
63    private javax.el.ValueExpression immediate;
64    private javax.el.ValueExpression transition;
65    private javax.el.ValueExpression converter;
66    private javax.el.ValueExpression renderedPartially;
67  
68    @Override
69    public int doStartTag() throws JspException {
70  
71      menuCommandTag = new MenuItemTag();
72      menuCommandTag.setPageContext(pageContext);
73      menuCommandTag.setParent(getParent());
74  
75      if (rendered != null) {
76        menuCommandTag.setRendered(rendered);
77      }
78      if (action != null) {
79        menuCommandTag.setAction(action);
80      }
81      if (actionListener != null) {
82        menuCommandTag.setActionListener(actionListener);
83      }
84      if (onclick != null) {
85        menuCommandTag.setOnclick(onclick);
86      }
87      if (link != null) {
88        menuCommandTag.setLink(link);
89      }
90      if (disabled != null) {
91        menuCommandTag.setDisabled(disabled);
92      }
93      if (binding != null) {
94        menuCommandTag.setBinding(binding);
95      }
96      if (label != null) {
97        menuCommandTag.setLabel(label);
98      }
99      if (immediate != null) {
100       menuCommandTag.setImmediate(immediate);
101     }
102     if (transition != null) {
103       menuCommandTag.setTransition(transition);
104     }
105     if (renderedPartially != null) {
106       menuCommandTag.setRenderedPartially(renderedPartially);
107     }
108     menuCommandTag.doStartTag();
109 
110     facetTag = new FacetTag();
111     facetTag.setPageContext(pageContext);
112     facetTag.setParent(menuCommandTag);
113     facetTag.setName(Facets.ITEMS);
114 
115     facetTag.doStartTag();
116     selectOneRadio = new SelectOneRadioTag();
117     selectOneRadio.setPageContext(pageContext);
118     selectOneRadio.setParent(facetTag);
119     if (converter != null) {
120       selectOneRadio.setConverter(converter);
121     }
122     if (value != null) {
123       selectOneRadio.setValue(value);
124     }
125     selectOneRadio.doStartTag();
126 
127     return super.doStartTag();
128   }
129 
130   @Override
131   public int doEndTag() throws JspException {
132 
133     if (renderedPartially == null) {
134       // Move attribute renderedPartially from selectOne to menuCommand component
135       UIComponent selectOneComponent = selectOneRadio.getComponentInstance();
136       UICommandBase command = (UICommandBase) menuCommandTag.getComponentInstance();
137       javax.el.ValueExpression expression = selectOneComponent.getValueExpression(Attributes.RENDERED_PARTIALLY);
138       if (expression != null) {
139         command.setValueExpression(Attributes.RENDERED_PARTIALLY, expression);
140       } else {
141         Object renderedPartially = selectOneComponent.getAttributes().get(Attributes.RENDERED_PARTIALLY);
142         command.setRenderedPartially(StringUtils.split((String) renderedPartially, ", "));
143       }
144     }
145 
146     selectOneRadio.doEndTag();
147     facetTag.doEndTag();
148     menuCommandTag.doEndTag();
149 
150     return super.doEndTag();
151   }
152 
153   /**
154    * Action to invoke when clicked.
155    * This must be a MethodBinding or a String representing the application action to invoke when
156    * this component is activated by the user.
157    * The MethodBinding must evaluate to a public method that takes no parameters,
158    * and returns a String (the logical outcome) which is passed to the
159    * NavigationHandler for this application.
160    * The String is directly passed to the Navigationhandler.
161    */
162   @TagAttribute
163   @UIComponentTagAttribute(type = {}, expression = DynamicExpression.METHOD_BINDING,
164       methodReturnType = "java.lang.Object")
165   public void setAction(javax.el.MethodExpression action) {
166     this.action = action;
167   }
168 
169   /**
170    * MethodBinding representing an action listener method that will be
171    * notified when this component is activated by the user.
172    * The expression must evaluate to a public method that takes an ActionEvent
173    * parameter, with a return type of void.
174    */
175   @TagAttribute
176   @UIComponentTagAttribute(type = {}, expression = DynamicExpression.METHOD_BINDING_REQUIRED,
177       methodSignature = "javax.faces.event.ActionEvent")
178   public void setActionListener(javax.el.MethodExpression actionListener) {
179     this.actionListener = actionListener;
180   }
181 
182   /**
183    * Script to be invoked when clicked
184    *
185    * @param onclick
186    */
187   @TagAttribute
188   @UIComponentTagAttribute()
189   public void setOnclick(javax.el.ValueExpression onclick) {
190     this.onclick = onclick;
191   }
192 
193   /**
194    * Link to an arbitrary URL
195    *
196    * @param link
197    */
198   @TagAttribute
199   @UIComponentTagAttribute()
200   public void setLink(javax.el.ValueExpression link) {
201     this.link = link;
202   }
203 
204   /**
205    * The value binding expression linking this
206    * component to a property in a backing bean.
207    */
208   @TagAttribute
209   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
210   public void setBinding(javax.el.ValueExpression binding) throws JspException {
211     this.binding = binding;
212   }
213 
214   /**
215    * Flag indicating whether or not this component should be rendered
216    * (during Render Response Phase), or processed on any subsequent form submit.
217    */
218   @TagAttribute
219   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.TRUE")
220   public void setRendered(javax.el.ValueExpression rendered) {
221     this.rendered = rendered;
222   }
223 
224   /**
225    * Flag indicating that this element is disabled.
226    */
227   @TagAttribute()
228   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.FALSE")
229   public void setDisabled(javax.el.ValueExpression disabled) {
230     this.disabled = disabled;
231   }
232 
233   /**
234    * The current value of this component.
235    */
236   @TagAttribute
237   @UIComponentTagAttribute(type = "java.lang.Object")
238   public void setValue(javax.el.ValueExpression value) {
239     this.value = value;
240   }
241 
242   /**
243    * Text value to display as label.
244    * If text contains an underscore the next character is used as accesskey.
245    */
246   @TagAttribute
247   @UIComponentTagAttribute()
248   public void setLabel(javax.el.ValueExpression label) {
249     this.label = label;
250   }
251 
252   /**
253    * Flag indicating that, if this component is activated by the user,
254    * notifications should be delivered to interested listeners and actions
255    * immediately (that is, during Apply Request Values phase) rather than
256    * waiting until Invoke Application phase.
257    */
258   @TagAttribute
259   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.FALSE")
260   public void setImmediate(javax.el.ValueExpression immediate) {
261     this.immediate = immediate;
262   }
263 
264   /**
265    * Specify, if the command calls an JSF-Action.
266    * Useful to switch off the Double-Submit-Check and Waiting-Behavior.
267    *
268    * @param transition Indicates the transition.
269    */
270   @TagAttribute
271   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "Boolean.TRUE")
272   public void setTransition(javax.el.ValueExpression transition) {
273     this.transition = transition;
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_BINDING)
288   public void setConverter(javax.el.ValueExpression converter) {
289     this.converter = converter;
290   }
291 
292   /**
293    * Indicate the partially rendered Components in a case of a submit.
294    */
295    @TagAttribute
296    @UIComponentTagAttribute(type = "java.lang.String[]")
297   public void setRenderedPartially(javax.el.ValueExpression renderedPartially) {
298     this.renderedPartially = renderedPartially;
299   }
300 
301   public void release() {
302     super.release();
303     rendered = null;
304     value = null;
305     action = null;
306     actionListener = null;
307     onclick = null;
308     link = null;
309     disabled = null;
310     binding = null;
311     label = null;
312     immediate = null;
313     transition = null;
314     converter = null;
315     renderedPartially = null;
316     menuCommandTag = null;
317     facetTag = null;
318     selectOneRadio = null;
319   }
320 
321 }