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.TagAttribute;
23  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
24  import org.apache.myfaces.tobago.component.Facets;
25  import org.apache.myfaces.tobago.internal.taglib.LabelTag;
26  import org.apache.myfaces.tobago.internal.taglib.SeparatorTag;
27  
28  import javax.faces.webapp.FacetTag;
29  import javax.servlet.jsp.JspException;
30  
31  /**
32   * Renders a separator.
33   * <br />
34   * Short syntax of:
35   * <p/>
36   * <pre>
37   * &lt;tc:separator>
38   *   &lt;f:facet name="label">
39   *     &lt;tc:label value="label"/>
40   *   &lt;/f:facet>
41   * &lt;/tc:separator>
42   * </pre>
43   */
44  
45  public class SeparatorExtensionTag extends TobagoExtensionBodyTagSupport {
46    
47    private javax.el.ValueExpression binding;
48    private javax.el.ValueExpression rendered;
49    private javax.el.ValueExpression label;
50  
51    private SeparatorTag separatorTag;
52    private FacetTag facetTag;
53    private LabelTag labelTag;
54  
55    @Override
56    public int doStartTag() throws JspException {
57      separatorTag = new SeparatorTag();
58      separatorTag.setPageContext(pageContext);
59      separatorTag.setParent(getParent());
60      if (binding != null) {
61        separatorTag.setBinding(binding);
62      }
63      if (rendered != null) {
64        separatorTag.setRendered(rendered);
65      }
66      facetTag = new FacetTag();
67      facetTag.setPageContext(pageContext);
68      facetTag.setParent(separatorTag);
69      facetTag.setName(Facets.LABEL);
70  
71      facetTag.doStartTag();
72      labelTag = new LabelTag();
73      labelTag.setPageContext(pageContext);
74      labelTag.setParent(facetTag);
75      if (label != null) {
76        labelTag.setValue(label);
77      }
78      labelTag.setJspId(nextJspId());
79      labelTag.doStartTag();
80      return super.doStartTag();
81    }
82  
83    @Override
84    public int doEndTag() throws JspException {
85      labelTag.doEndTag();
86      facetTag.doEndTag();
87      separatorTag.doEndTag();
88      return super.doEndTag();
89    }
90  
91    @Override
92    public void release() {
93      super.release();
94      binding = null;
95      rendered = null;
96      label = null;
97      separatorTag = null;
98      facetTag = null;
99      labelTag = null;
100   }
101 
102   /**
103    * The value binding expression linking this
104    * component to a property in a backing bean.
105    */
106   @TagAttribute
107   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
108   public void setBinding(javax.el.ValueExpression binding) throws JspException {
109     this.binding = binding;
110   }
111   
112   /**
113    * Flag indicating whether or not this component should be rendered
114    * (during Render Response Phase), or processed on any subsequent form submit.
115    */
116   @TagAttribute
117   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
118   public void setRendered(javax.el.ValueExpression rendered) {
119     this.rendered = rendered;
120   }
121 
122   /**
123    * Text value to display as label.
124    * If text contains an underscore the next character is used as accesskey.
125    */
126   @TagAttribute
127   @UIComponentTagAttribute()
128   public void setLabel(javax.el.ValueExpression label) {
129     this.label = label;
130   }
131 }