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