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 javax.faces.render;
20  
21  import java.io.IOException;
22  
23  import javax.faces.component.UIComponent;
24  import javax.faces.context.FacesContext;
25  import javax.faces.convert.ConverterException;
26  
27  /**
28   * see Javadoc of <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/index.html">JSF Specification</a>
29   * 
30   * @author Manfred Geiler (latest modification by $Author: struberg $)
31   * @version $Revision: 1188235 $ $Date: 2011-10-24 17:09:33 +0000 (Mon, 24 Oct 2011) $
32   */
33  public abstract class Renderer
34  {
35      public void decode(FacesContext context, UIComponent component)
36      {
37          if (context == null)
38          {
39              throw new NullPointerException("context");
40          }
41          if (component == null)
42          {
43              throw new NullPointerException("component");
44          }
45      }
46  
47      /**
48       * @throws IOException if an input/output error occurs while rendering 
49       */
50      public void encodeBegin(FacesContext context, UIComponent component) throws IOException
51      {
52          if (context == null)
53          {
54              throw new NullPointerException("context");
55          }
56          if (component == null)
57          {
58              throw new NullPointerException("component");
59          }
60      }
61  
62      /**
63       * Render all children if there are any.
64       * 
65       * Note: this will only be called if getRendersChildren() returns true. A component which has a renderer with
66       * getRendersChildren() set to true will typically contain the rendering logic for its children in this method.
67       * 
68       * @param context
69       * @param component
70       * @throws IOException
71       */
72      public void encodeChildren(FacesContext context, UIComponent component) throws IOException
73      {
74          if (context == null)
75          {
76              throw new NullPointerException("context");
77          }
78          if (component == null)
79          {
80              throw new NullPointerException("component");
81          }
82  
83          if (component.getChildCount() > 0)
84          {
85              for (int i = 0, childCount = component.getChildCount(); i < childCount; i++)
86              {
87                  UIComponent child = component.getChildren().get(i);
88                  if (!child.isRendered())
89                  {
90                      continue;
91                  }
92  
93                  child.encodeAll(context);
94              }
95          }
96      }
97  
98      /**
99       * @throws IOException if an input/output error occurs while rendering 
100      */
101     public void encodeEnd(FacesContext context, UIComponent component) throws IOException
102     {
103         if (context == null)
104         {
105             throw new NullPointerException("context");
106         }
107         if (component == null)
108         {
109             throw new NullPointerException("component");
110         }
111     }
112 
113     public String convertClientId(FacesContext context, String clientId)
114     {
115         if (context == null)
116         {
117             throw new NullPointerException("context");
118         }
119         if (clientId == null)
120         {
121             throw new NullPointerException("clientId");
122         }
123         return clientId;
124     }
125 
126     /**
127      * Switch for deciding who renders the children.
128      * 
129      * @return <b>true</b> - if the component takes care of rendering its children. In this case, encodeChildren() ought
130      *         to be called by the rendering controller (e.g., the rendering controller could be the method encodeAll()
131      *         in UIComponent). In the method encodeChildren(), the component should therefore provide all children
132      *         encode logic. <br/> <b>false</b> - if the component does not take care of rendering its children. In this
133      *         case, encodeChildren() should not be called by the rendering controller. Instead, the children-list
134      *         should be retrieved and the children should directly be rendered by the rendering controller one by one.
135      */
136     public boolean getRendersChildren()
137     {
138         return false;
139     }
140 
141     public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
142         throws ConverterException
143     {
144         if (context == null)
145         {
146             throw new NullPointerException("context");
147         }
148         if (component == null)
149         {
150             throw new NullPointerException("component");
151         }
152         return submittedValue;
153     }
154 
155 }