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.renderkit.html;
20  
21  import org.apache.myfaces.shared.renderkit.RendererUtils;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.component.UIViewRoot;
25  import javax.faces.component.html.HtmlPanelGroup;
26  import javax.faces.context.FacesContext;
27  import javax.faces.context.ResponseWriter;
28  import java.io.IOException;
29  
30  /**
31   * @author Martin Marinschek
32   * @version $Revision: 1187701 $ $Date: 2011-10-22 07:21:54 -0500 (Sat, 22 Oct 2011) $
33   *          <p/>
34   *          $Log: $
35   */
36  public class HtmlGroupRendererBase
37          extends HtmlRenderer 
38  {
39      private static final String LAYOUT_BLOCK_VALUE = "block";
40  
41      public boolean getRendersChildren()
42      {
43          return true;
44      }
45  
46      public void encodeBegin(FacesContext context, UIComponent component)
47              throws IOException
48      {
49      }
50  
51      public void encodeChildren(FacesContext context, UIComponent component)
52          throws IOException
53      {
54      }
55  
56      public void encodeEnd(FacesContext context, UIComponent component)
57              throws IOException
58      {
59          ResponseWriter writer = context.getResponseWriter();
60          boolean span = false;
61  
62          // will be SPAN or DIV, depending on the layout attribute value
63          String layoutElement = HTML.SPAN_ELEM;
64  
65          HtmlPanelGroup panelGroup = (HtmlPanelGroup) component;
66  
67          // if layout is 'block', render DIV instead SPAN
68          String layout = panelGroup.getLayout();
69          if (layout != null && layout.equals(LAYOUT_BLOCK_VALUE))
70          {
71              layoutElement = HTML.DIV_ELEM;
72          }
73  
74          if(component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
75          {
76              span = true;
77  
78              writer.startElement(layoutElement, component);
79  
80              HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
81  
82              if (isCommonPropertiesOptimizationEnabled(context))
83              {
84                  CommonPropertyUtils.renderCommonPassthroughProperties(writer, 
85                          CommonPropertyUtils.getCommonPropertiesMarked(component), component);
86              }
87              else
88              {
89                  HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
90              }
91          }
92          else
93          {
94              if (isCommonPropertiesOptimizationEnabled(context))
95              {
96                  long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component);
97                  if (commonPropertiesMarked > 0)
98                  {
99                      span = true;
100                     writer.startElement(layoutElement, component);
101                     HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
102 
103                     CommonPropertyUtils.renderCommonPassthroughProperties(writer, commonPropertiesMarked, component);
104                 }
105             }
106             else
107             {
108                 span=HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,
109                                                                                  component,
110                                                                                  layoutElement,
111                                                                                  HTML.COMMON_PASSTROUGH_ATTRIBUTES);
112             }
113         }
114 
115         RendererUtils.renderChildren(context, component);
116         if (span)
117         {
118             writer.endElement(layoutElement);
119         }
120     }
121 
122 }