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  package org.apache.myfaces.shared_orchestra.renderkit.html;
20  
21  import org.apache.myfaces.shared_orchestra.renderkit.RendererUtils;
22  import org.apache.myfaces.shared_orchestra.renderkit.html.HTML;
23  
24  import javax.faces.context.FacesContext;
25  import javax.faces.context.ResponseWriter;
26  import javax.faces.component.UIComponent;
27  import javax.faces.component.UIViewRoot;
28  import java.io.IOException;
29  
30  /**
31   * @author Martin Marinschek
32   * @version $Revision: $ $Date: $
33   *          <p/>
34   *          $Log: $
35   */
36  public class HtmlGroupRendererBase
37          extends HtmlRenderer 
38  {
39      public boolean getRendersChildren()
40      {
41          return true;
42      }
43  
44      public void encodeBegin(FacesContext context, UIComponent component)
45              throws IOException
46      {
47      }
48  
49      public void encodeChildren(FacesContext context, UIComponent component)
50          throws IOException
51      {
52      }
53  
54      public void encodeEnd(FacesContext context, UIComponent component)
55              throws IOException
56      {
57          ResponseWriter writer = context.getResponseWriter();
58          boolean span = false;
59  
60          if(component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
61          {
62              span = true;
63  
64              writer.startElement(org.apache.myfaces.shared_orchestra.renderkit.html.HTML.SPAN_ELEM, component);
65  
66              HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
67  
68              HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
69          }
70          else
71          {
72              span=HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,
73                                                                               component,
74                                                                               HTML.SPAN_ELEM,
75                                                                               HTML.COMMON_PASSTROUGH_ATTRIBUTES);
76          }
77  
78          RendererUtils.renderChildren(context, component);
79          if (span)
80          {
81              writer.endElement(HTML.SPAN_ELEM);
82          }
83      }
84  
85  }