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;
20  
21  import java.io.IOException;
22  import java.util.logging.Logger;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  
27  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
28  import org.apache.myfaces.shared.renderkit.html.HtmlRenderer;
29  
30  /**
31   * 
32   * @author Leonardo Uribe (latest modification by $Author: struberg $)
33   * @version $Revision: 1188235 $ $Date: 2011-10-24 12:09:33 -0500 (Mon, 24 Oct 2011) $
34   */
35  @JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Output", type = "javax.faces.CompositeFacet")
36  public class HtmlCompositeFacetRenderer extends HtmlRenderer
37  {
38      //private static final Log log = LogFactory.getLog(HtmlCompositeFacetRenderer.class);
39      private static final Logger log = Logger.getLogger(HtmlCompositeFacetRenderer.class.getName());
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          if (context == null)
55          {
56              throw new NullPointerException("context");
57          }
58          if (component == null)
59          {
60              throw new NullPointerException("component");
61          }
62          
63          String facetName = (String) component.getAttributes().get(UIComponent.FACETS_KEY);
64          
65          if (facetName == null)
66          {
67              throw new IOException("Composite facet name under key UIComponent.FACETS_KEY not found "+
68                      component.getClientId(context));
69          }
70          
71          UIComponent compositeComponent = UIComponent.getCurrentCompositeComponent(context);
72          
73          if (compositeComponent == null)
74          {
75              throw new IOException("parent Composite Component not found when rendering composite component facet "+
76                      component.getClientId(context));
77          }
78          
79          UIComponent compositeFacet = (UIComponent) compositeComponent.getFacet(facetName);
80          
81          if (compositeFacet != null)
82          {
83              compositeFacet.encodeAll(context);
84          }
85      }
86  
87      public void encodeEnd(FacesContext context, UIComponent component)
88              throws IOException
89      {
90      }
91  }