1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.shared.renderkit.html; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import javax.faces.application.ProjectStage; |
26 | |
import javax.faces.component.UIComponent; |
27 | |
import javax.faces.component.UIViewRoot; |
28 | |
import javax.faces.component.behavior.ClientBehavior; |
29 | |
import javax.faces.component.behavior.ClientBehaviorHolder; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
import javax.faces.context.ResponseWriter; |
32 | |
|
33 | |
import org.apache.myfaces.shared.renderkit.ClientBehaviorEvents; |
34 | |
import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class HtmlBodyRendererBase extends HtmlRenderer |
42 | |
{ |
43 | |
|
44 | |
@Override |
45 | |
public void decode(FacesContext context, UIComponent component) |
46 | |
{ |
47 | |
|
48 | 0 | super.decode(context, component); |
49 | |
|
50 | 0 | HtmlRendererUtils.decodeClientBehaviors(context, component); |
51 | 0 | } |
52 | |
|
53 | |
@Override |
54 | |
public void encodeBegin(FacesContext facesContext, UIComponent component) |
55 | |
throws IOException |
56 | |
{ |
57 | 0 | super.encodeBegin(facesContext, component); |
58 | |
|
59 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
60 | 0 | Map<String, List<ClientBehavior>> behaviors = null; |
61 | 0 | if (component instanceof ClientBehaviorHolder) |
62 | |
{ |
63 | 0 | behaviors = ((ClientBehaviorHolder) component).getClientBehaviors(); |
64 | 0 | if (!behaviors.isEmpty()) |
65 | |
{ |
66 | 0 | ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer); |
67 | |
} |
68 | |
|
69 | 0 | writer.startElement(HTML.BODY_ELEM, component); |
70 | 0 | if (!behaviors.isEmpty()) |
71 | |
{ |
72 | |
|
73 | 0 | writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext),null); |
74 | |
} |
75 | |
else |
76 | |
{ |
77 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext); |
78 | |
} |
79 | 0 | if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) |
80 | |
{ |
81 | 0 | CommonPropertyUtils.renderEventProperties(writer, |
82 | |
CommonPropertyUtils.getCommonPropertiesMarked(component), component); |
83 | |
} |
84 | |
else |
85 | |
{ |
86 | 0 | if (isCommonEventsOptimizationEnabled(facesContext)) |
87 | |
{ |
88 | 0 | CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, |
89 | |
CommonPropertyUtils.getCommonPropertiesMarked(component), |
90 | |
CommonEventUtils.getCommonEventsMarked(component), component, behaviors); |
91 | |
} |
92 | |
else |
93 | |
{ |
94 | 0 | HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, behaviors); |
95 | |
} |
96 | |
} |
97 | 0 | HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONLOAD_ATTR, component, |
98 | |
ClientBehaviorEvents.LOAD, behaviors, HTML.ONLOAD_ATTR); |
99 | 0 | HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONUNLOAD_ATTR, component, |
100 | |
ClientBehaviorEvents.UNLOAD, behaviors, HTML.ONUNLOAD_ATTR); |
101 | 0 | if (isCommonPropertiesOptimizationEnabled(facesContext)) |
102 | |
{ |
103 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, |
104 | |
HTML.BODY_ATTRIBUTES_WITHOUT_EVENTS); |
105 | 0 | CommonPropertyUtils.renderCommonPassthroughPropertiesWithoutEvents(writer, |
106 | |
CommonPropertyUtils.getCommonPropertiesMarked(component), component); |
107 | |
} |
108 | |
else |
109 | |
{ |
110 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, |
111 | |
HTML.BODY_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS); |
112 | |
} |
113 | 0 | HtmlRendererUtils.renderHTMLStringAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR); |
114 | |
|
115 | |
} |
116 | |
else |
117 | |
{ |
118 | 0 | writer.startElement(HTML.BODY_ELEM, component); |
119 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext); |
120 | 0 | if (isCommonPropertiesOptimizationEnabled(facesContext)) |
121 | |
{ |
122 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, |
123 | |
HTML.BODY_ATTRIBUTES); |
124 | 0 | CommonPropertyUtils.renderCommonPassthroughProperties(writer, |
125 | |
CommonPropertyUtils.getCommonPropertiesMarked(component), component); |
126 | |
} |
127 | |
else |
128 | |
{ |
129 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, |
130 | |
HTML.BODY_PASSTHROUGH_ATTRIBUTES); |
131 | |
} |
132 | 0 | HtmlRendererUtils.renderHTMLStringAttribute(writer, component, HTML.XMLNS_ATTR , HTML.XMLNS_ATTR); |
133 | |
} |
134 | 0 | } |
135 | |
|
136 | |
@Override |
137 | |
public void encodeEnd(FacesContext facesContext, UIComponent component) |
138 | |
throws IOException |
139 | |
{ |
140 | 0 | super.encodeEnd(facesContext, component); |
141 | |
|
142 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
143 | 0 | UIViewRoot root = facesContext.getViewRoot(); |
144 | |
|
145 | |
|
146 | 0 | List<UIComponent> componentResources = root.getComponentResources(facesContext, |
147 | |
HTML.BODY_TARGET); |
148 | 0 | int childrenCount = componentResources.size(); |
149 | 0 | if (childrenCount > 0) |
150 | |
{ |
151 | 0 | for (int i = 0; i < childrenCount; i++) |
152 | |
{ |
153 | 0 | UIComponent child = componentResources.get(i); |
154 | 0 | child.encodeAll(facesContext); |
155 | |
} |
156 | |
} |
157 | |
|
158 | |
|
159 | 0 | if (facesContext.isProjectStage(ProjectStage.Development)) |
160 | |
{ |
161 | 0 | HtmlRendererUtils.renderUnhandledFacesMessages(facesContext); |
162 | |
} |
163 | |
|
164 | 0 | writer.endElement(HTML.BODY_ELEM); |
165 | 0 | } |
166 | |
} |