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