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.renderkit.html.ext;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.component.UIViewRoot;
25  import javax.faces.context.FacesContext;
26  import javax.faces.context.ResponseWriter;
27  
28  import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
29  import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
30  import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
31  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlGroupRendererBase;
32  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
33  
34  
35  /**
36   * @JSFRenderer
37   *   renderKitId = "HTML_BASIC"
38   *   family = "javax.faces.Panel"
39   *   type = "org.apache.myfaces.Group"
40   * 
41   * @author Martin Marinschek (latest modification by $Author: mmarinschek $)
42   * @version $Revision: 167446 $ $Date: 2004-12-23 13:03:09Z $
43   */
44  public class HtmlGroupRenderer
45      extends HtmlGroupRendererBase
46  {
47      
48      public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
49          ResponseWriter writer = context.getResponseWriter();
50          boolean span = false;
51          String element = getHtmlElement(component);
52          
53          if(component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
54          {
55              span = true;
56  
57              writer.startElement(element, component);
58  
59              HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
60  
61              HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
62          }
63          else
64          {
65              span=HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,
66                                                                               component,
67                                                                               element,
68                                                                               HTML.COMMON_PASSTROUGH_ATTRIBUTES);
69          }
70  
71          RendererUtils.renderChildren(context, component);
72          if (span)
73          {
74              writer.endElement(element);
75          }
76      }
77      
78      private String getHtmlElement(UIComponent component) {
79          if (component instanceof HtmlPanelGroup) {
80              HtmlPanelGroup group = (HtmlPanelGroup) component;
81              if (HtmlPanelGroup.BLOCK_LAYOUT.equals(group.getLayout())) {
82                  return HTML.DIV_ELEM;
83              }
84          }
85          return HTML.SPAN_ELEM;
86      }
87  }