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.custom.div;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.Map;
24  
25  import javax.faces.component.UIComponent;
26  import javax.faces.component.behavior.ClientBehavior;
27  import javax.faces.context.FacesContext;
28  import javax.faces.context.ResponseWriter;
29  
30  import org.apache.myfaces.custom.htmlTag.HtmlTagRenderer;
31  import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
32  import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
33  import org.apache.myfaces.shared_tomahawk.renderkit.html.util.ResourceUtils;
34  
35  /**
36   * @JSFRenderer
37   *   renderKitId = "HTML_BASIC" 
38   *   family = "javax.faces.Output"
39   *   type = "org.apache.myfaces.DivRenderer"
40   * @since 1.1.7
41   * @author bdudney (latest modification by $Author: lu4242 $)
42   * @version $Revision: 691871 $ $Date: 2008-09-03 23:32:08 -0500 (miƩ, 03 sep 2008) $
43   */
44  public class DivRenderer extends HtmlTagRenderer
45  {
46      public static final String RENDERER_TYPE = "org.apache.myfaces.HtmlTagRenderer";
47  
48      @Override
49      public void decode(FacesContext context, UIComponent component)
50      {
51          super.decode(context, component);
52          
53          HtmlRendererUtils.decodeClientBehaviors(context, component);
54      }
55  
56      public void encodeBegin(FacesContext context, UIComponent component)
57              throws IOException
58      {
59          if ((context == null) || (component == null))
60          {
61              throw new NullPointerException();
62          }
63          
64          Div div = (Div) component;
65          Map<String, List<ClientBehavior>> behaviors = div.getClientBehaviors();
66          if (behaviors != null && !behaviors.isEmpty())
67          {
68              ResourceUtils.renderDefaultJsfJsInlineIfNecessary(context, context.getResponseWriter());
69          }
70  
71          super.encodeBegin(context, component);
72  
73          if (div.isRendered())
74          {
75              ResponseWriter writer = context.getResponseWriter();
76              //Previously, style and styleClass was rendered,
77              //so on div renderer we need to add event and universal
78              //attributes only
79              if (behaviors != null && !behaviors.isEmpty())
80              {
81                  HtmlRendererUtils.writeIdAndName(writer, component, context);
82                  HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.UNIVERSAL_ATTRIBUTES_WITHOUT_STYLE);
83                  HtmlRendererUtils.renderBehaviorizedEventHandlers(context, writer, component, behaviors);
84              }
85              else
86              {
87                  HtmlRendererUtils.renderHTMLAttributes(writer, div, 
88                          HTML.COMMON_PASSTROUGH_ATTRIBUTES_WITHOUT_STYLE);
89              }
90          }
91      }
92  
93  }