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  
23  import javax.faces.component.UIComponent;
24  import javax.faces.context.FacesContext;
25  
26  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
27  import org.apache.myfaces.shared.renderkit.html.HtmlRenderer;
28  
29  /**
30   * 
31   * @author Leonardo Uribe (latest modification by $Author$)
32   * @version $Revision$ $Date$
33   */
34  @JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Output", type = "javax.faces.CompositeFacet")
35  public class HtmlCompositeFacetRenderer extends HtmlRenderer
36  {
37      
38      public boolean getRendersChildren()
39      {
40          return true;
41      }
42  
43      public void encodeBegin(FacesContext context, UIComponent component)
44              throws IOException
45      {
46      }
47  
48      public void encodeChildren(FacesContext context, UIComponent component)
49              throws IOException
50      {
51          if (context == null)
52          {
53              throw new NullPointerException("context");
54          }
55          if (component == null)
56          {
57              throw new NullPointerException("component");
58          }
59          
60          String facetName = (String) component.getAttributes().get(UIComponent.FACETS_KEY);
61          
62          if (facetName == null)
63          {
64              throw new IOException("Composite facet name under key UIComponent.FACETS_KEY not found "+
65                      component.getClientId(context));
66          }
67          
68          UIComponent compositeComponent = UIComponent.getCurrentCompositeComponent(context);
69          
70          if (compositeComponent == null)
71          {
72              throw new IOException("parent Composite Component not found when rendering composite component facet "+
73                      component.getClientId(context));
74          }
75          
76          UIComponent compositeFacet = (UIComponent) compositeComponent.getFacet(facetName);
77          
78          if (compositeFacet != null)
79          {
80              compositeFacet.encodeAll(context);
81          }
82      }
83  
84      public void encodeEnd(FacesContext context, UIComponent component)
85              throws IOException
86      {
87      }
88  }