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: lu4242 $)
33   * @version $Revision: 1151677 $ $Date: 2011-07-27 19:03:59 -0500 (Wed, 27 Jul 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              throw new NullPointerException("context");
56          if (component == null)
57              throw new NullPointerException("component");
58          
59          String facetName = (String) component.getAttributes().get(UIComponent.FACETS_KEY);
60          
61          if (facetName == null)
62          {
63              throw new IOException("Composite facet name under key UIComponent.FACETS_KEY not found "+
64                      component.getClientId(context));
65          }
66          
67          UIComponent compositeComponent = UIComponent.getCurrentCompositeComponent(context);
68          
69          if (compositeComponent == null)
70          {
71              throw new IOException("parent Composite Component not found when rendering composite component facet "+
72                      component.getClientId(context));
73          }
74          
75          UIComponent compositeFacet = (UIComponent) compositeComponent.getFacet(facetName);
76          
77          if (compositeFacet != null)
78          {
79              compositeFacet.encodeAll(context);
80          }
81      }
82  
83      public void encodeEnd(FacesContext context, UIComponent component)
84              throws IOException
85      {
86      }
87  }