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