1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.component; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
import javax.faces.FacesException; |
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 | |
import javax.faces.render.Renderer; |
30 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer; |
31 | |
import org.apache.myfaces.shared.renderkit.ClientBehaviorEvents; |
32 | |
import org.apache.myfaces.shared.renderkit.RendererUtils; |
33 | |
import org.apache.myfaces.shared.renderkit.html.CommonEventUtils; |
34 | |
import org.apache.myfaces.shared.renderkit.html.CommonPropertyUtils; |
35 | |
import org.apache.myfaces.shared.renderkit.html.HTML; |
36 | |
import org.apache.myfaces.shared.renderkit.html.HtmlRenderer; |
37 | |
import org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils; |
38 | |
import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@JSFRenderer( |
45 | |
renderKitId = "HTML_BASIC", |
46 | |
family = "javax.faces.Panel", |
47 | |
type = "javax.faces.passthrough.Element") |
48 | 0 | public class JsfElementRenderer extends HtmlRenderer |
49 | |
{ |
50 | |
|
51 | |
public boolean getRendersChildren() |
52 | |
{ |
53 | 0 | return true; |
54 | |
} |
55 | |
|
56 | |
@Override |
57 | |
public void decode(FacesContext context, UIComponent component) |
58 | |
{ |
59 | |
|
60 | 0 | super.decode(context, component); |
61 | |
|
62 | 0 | HtmlRendererUtils.decodeClientBehaviors(context, component); |
63 | 0 | } |
64 | |
|
65 | |
public void encodeBegin(FacesContext facesContext, UIComponent component) |
66 | |
throws IOException |
67 | |
{ |
68 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
69 | 0 | String elementName = (String) |
70 | |
component.getPassThroughAttributes().get(Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY); |
71 | |
|
72 | 0 | if (elementName == null) |
73 | |
{ |
74 | 0 | throw new FacesException("jsf:element with clientId" |
75 | |
+ component.getClientId(facesContext) + " requires 'elementName' passthrough attribute"); |
76 | |
} |
77 | 0 | JsfElement jsfElement = (JsfElement) component; |
78 | 0 | Map<String, List<ClientBehavior>> behaviors = jsfElement.getClientBehaviors(); |
79 | |
|
80 | 0 | if (behaviors != null && !behaviors.isEmpty()) |
81 | |
{ |
82 | 0 | ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer); |
83 | |
} |
84 | |
|
85 | 0 | writer.startElement(elementName, component); |
86 | |
|
87 | 0 | if (!behaviors.isEmpty()) |
88 | |
{ |
89 | 0 | HtmlRendererUtils.writeIdAndName(writer, component, facesContext); |
90 | |
} |
91 | |
else |
92 | |
{ |
93 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext); |
94 | |
} |
95 | |
|
96 | |
|
97 | 0 | long commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component); |
98 | 0 | if (behaviors.isEmpty()) |
99 | |
{ |
100 | 0 | CommonPropertyUtils.renderEventProperties(writer, commonPropertiesMarked, component); |
101 | 0 | CommonPropertyUtils.renderFocusBlurEventProperties(writer, commonPropertiesMarked, component); |
102 | 0 | CommonPropertyUtils.renderChangeSelectEventProperties(writer, commonPropertiesMarked, component); |
103 | |
} |
104 | |
else |
105 | |
{ |
106 | 0 | long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(component); |
107 | 0 | CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, |
108 | |
commonPropertiesMarked, commonEventsMarked, component, behaviors); |
109 | 0 | CommonEventUtils.renderBehaviorizedFieldEventHandlers(facesContext, writer, |
110 | |
commonPropertiesMarked, commonEventsMarked, component, |
111 | |
component.getClientId(facesContext), behaviors); |
112 | |
} |
113 | 0 | CommonPropertyUtils.renderStyleProperties(writer, commonPropertiesMarked, component); |
114 | 0 | HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONLOAD_ATTR, component, |
115 | |
ClientBehaviorEvents.LOAD, behaviors, HTML.ONLOAD_ATTR); |
116 | 0 | HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONUNLOAD_ATTR, component, |
117 | |
ClientBehaviorEvents.UNLOAD, behaviors, HTML.ONUNLOAD_ATTR); |
118 | |
|
119 | 0 | } |
120 | |
|
121 | |
public void encodeChildren(FacesContext facesContext, UIComponent component) |
122 | |
throws IOException |
123 | |
{ |
124 | 0 | RendererUtils.renderChildren(facesContext, component); |
125 | 0 | } |
126 | |
|
127 | |
public void encodeEnd(FacesContext facesContext, UIComponent component) |
128 | |
throws IOException |
129 | |
{ |
130 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
131 | 0 | String elementName = (String) component.getPassThroughAttributes().get( |
132 | |
Renderer.PASSTHROUGH_RENDERER_LOCALNAME_KEY); |
133 | 0 | writer.endElement(elementName); |
134 | 0 | } |
135 | |
|
136 | |
protected boolean isCommonPropertiesOptimizationEnabled(FacesContext facesContext) |
137 | |
{ |
138 | 0 | return true; |
139 | |
} |
140 | |
|
141 | |
protected boolean isCommonEventsOptimizationEnabled(FacesContext facesContext) |
142 | |
{ |
143 | 0 | return true; |
144 | |
} |
145 | |
} |