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