1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.custom.dojolayouts;
21
22 import java.io.IOException;
23
24 import javax.faces.component.UIComponent;
25 import javax.faces.context.FacesContext;
26 import javax.faces.context.ResponseWriter;
27
28 import org.apache.myfaces.component.StyleAware;
29 import org.apache.myfaces.custom.dojo.DojoConfig;
30 import org.apache.myfaces.custom.dojo.DojoUtils;
31 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
32 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
33 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
34 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class DojoContentPaneRenderer extends HtmlRenderer {
50
51 public void decode(FacesContext context, UIComponent component) {
52 super.decode(context, component);
53
54 }
55
56 protected void encodeJavascriptBegin(FacesContext context, UIComponent component) throws IOException {
57 String javascriptLocation = (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
58 try {
59 if (javascriptLocation != null) {
60 DojoUtils.addMainInclude(context, component, javascriptLocation, new DojoConfig());
61 } else {
62 DojoUtils.addMainInclude(context, component, null, new DojoConfig());
63 }
64 }
65
66 catch (IOException e) {
67 e.printStackTrace();
68 }
69 DojoUtils.addRequire(context, component, "dojo.widget.ContentPane");
70 }
71
72 public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
73 if ((context == null) || (component == null)) {
74 throw new NullPointerException();
75 }
76
77 Boolean rendered = (Boolean) component.getAttributes().get("rendered");
78
79 if ((rendered != null) && (!rendered.booleanValue()))
80 return;
81 encodeJavascriptBegin(context, component);
82
83 super.encodeBegin(context, component);
84
85 ResponseWriter writer = context.getResponseWriter();
86 writer.startElement(HTML.DIV_ELEM, component);
87 HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
88
89 StyleAware pane = (StyleAware) component;
90
91 String styleClass = pane.getStyleClass();
92 String style = pane.getStyle();
93 if (null != styleClass) {
94 writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
95 }
96 if (null != style) {
97 writer.writeAttribute(HTML.STYLE_ATTR, style, null);
98 }
99
100 }
101
102 public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
103
104
105 super.encodeChildren(context, component);
106 }
107
108 public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
109 super.encodeEnd(context, component);
110 ResponseWriter writer = context.getResponseWriter();
111 writer.endElement(HTML.DIV_ELEM);
112 encodeJavascriptEnd(context, component);
113 }
114
115 protected void encodeJavascriptEnd(FacesContext context, UIComponent component) throws IOException {
116
117 String [] attributeNames = {"sizeShare", "id", "adjustPaths", "executeScripts",
118 "extractContent", "handler", "href", "layoutAlign",
119 "parseContent", "preload", "refreshOnShow", "widgetVar", "widgetId"};
120
121 DojoUtils.renderWidgetInitializationCode(context, component, "ContentPane", attributeNames);
122 }
123
124 public boolean getRendersChildren() {
125 return true;
126 }
127
128 }