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.view.facelets.component;
20  
21  import java.io.IOException;
22  import java.util.Map;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.context.FacesContext;
26  import javax.faces.context.ResponseWriter;
27  import javax.faces.render.Renderer;
28  
29  import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
30  
31  @JSFRenderer(family="facelets",
32          renderKitId="HTML_BASIC",
33          type="facelets.ui.Repeat")
34  public class RepeatRenderer extends Renderer
35  {
36  
37      public RepeatRenderer()
38      {
39          super();
40      }
41  
42      @Override
43      public void encodeBegin(FacesContext context, UIComponent component) throws IOException
44      {
45  
46      }
47  
48      @Override
49      public void encodeChildren(FacesContext context, UIComponent component) throws IOException
50      {
51          if (component.getChildCount() > 0)
52          {
53              Map<String, Object> a = component.getAttributes();
54              String tag = (String) a.get("alias.element");
55              if (tag != null)
56              {
57                  ResponseWriter out = context.getResponseWriter();
58                  out.startElement(tag, component);
59                  String[] attrs = (String[]) a.get("alias.attributes");
60                  String attr;
61                  if (attrs != null)
62                  {
63                      for (int i = 0; i < attrs.length; i++)
64                      {
65                          attr = attrs[i];
66                          if ("styleClass".equals(attr))
67                          {
68                              attr = "class";
69                          }
70                          out.writeAttribute(attr, a.get(attrs[i]), attrs[i]);
71                      }
72                  }
73              }
74              
75              for (int i = 0, childCount = component.getChildCount(); i < childCount; i++)
76              {
77                  UIComponent child = component.getChildren().get(i);
78                  child.encodeAll(context);
79              }
80  
81              if (tag != null)
82              {
83                  context.getResponseWriter().endElement(tag);
84              }
85          }
86      }
87  
88      @Override
89      public void encodeEnd(FacesContext context, UIComponent component) throws IOException
90      {
91          
92      }
93  
94      @Override
95      public boolean getRendersChildren()
96      {
97          return true;
98      }
99  
100 }