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