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 org.apache.myfaces.shared.renderkit.JSFAttr; |
22 | |
import org.apache.myfaces.shared.renderkit.RendererUtils; |
23 | |
import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils; |
24 | |
|
25 | |
import javax.faces.component.UIComponent; |
26 | |
import javax.faces.component.UIInput; |
27 | |
import javax.faces.component.UIOutput; |
28 | |
import javax.faces.component.behavior.ClientBehavior; |
29 | |
import javax.faces.component.behavior.ClientBehaviorHolder; |
30 | |
import javax.faces.component.html.HtmlInputSecret; |
31 | |
import javax.faces.context.FacesContext; |
32 | |
import javax.faces.context.ResponseWriter; |
33 | |
import javax.faces.convert.ConverterException; |
34 | |
import java.io.IOException; |
35 | |
import java.util.List; |
36 | |
import java.util.Map; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class HtmlSecretRendererBase |
43 | |
extends HtmlRenderer |
44 | |
{ |
45 | |
private static final String AUTOCOMPLETE_VALUE_OFF = "off"; |
46 | |
|
47 | |
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) |
48 | |
throws IOException |
49 | |
{ |
50 | 0 | RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class); |
51 | |
|
52 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
53 | |
|
54 | 0 | Map<String, List<ClientBehavior>> behaviors = null; |
55 | 0 | if (uiComponent instanceof ClientBehaviorHolder) |
56 | |
{ |
57 | 0 | behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors(); |
58 | 0 | if (!behaviors.isEmpty()) |
59 | |
{ |
60 | 0 | ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer); |
61 | |
} |
62 | |
} |
63 | |
|
64 | |
|
65 | 0 | renderInputBegin(facesContext, uiComponent); |
66 | 0 | renderInputEnd(facesContext, uiComponent); |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
protected void renderInputBegin(FacesContext facesContext, |
72 | |
UIComponent uiComponent) throws IOException |
73 | |
{ |
74 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
75 | |
|
76 | 0 | writer.startElement(HTML.INPUT_ELEM, uiComponent); |
77 | 0 | writer.writeAttribute(HTML.TYPE_ATTR, org.apache.myfaces.shared.renderkit.html.HTML.INPUT_TYPE_PASSWORD, null); |
78 | |
|
79 | 0 | if (uiComponent instanceof ClientBehaviorHolder |
80 | |
&& !((ClientBehaviorHolder) uiComponent).getClientBehaviors().isEmpty()) |
81 | |
{ |
82 | 0 | writer.writeAttribute(HTML.ID_ATTR, |
83 | |
uiComponent.getClientId(facesContext), null); |
84 | |
} |
85 | |
else |
86 | |
{ |
87 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext); |
88 | |
} |
89 | 0 | writer.writeAttribute(HTML.NAME_ATTR, |
90 | |
uiComponent.getClientId(facesContext), null); |
91 | |
|
92 | |
boolean isRedisplay; |
93 | 0 | if (uiComponent instanceof HtmlInputSecret) |
94 | |
{ |
95 | 0 | isRedisplay = ((HtmlInputSecret)uiComponent).isRedisplay(); |
96 | |
} |
97 | |
else |
98 | |
{ |
99 | 0 | isRedisplay = org.apache.myfaces.shared.renderkit.RendererUtils.getBooleanAttribute(uiComponent, |
100 | |
JSFAttr.REDISPLAY_ATTR, false); |
101 | |
} |
102 | 0 | if (isRedisplay) |
103 | |
{ |
104 | 0 | String strValue = RendererUtils.getStringValue(facesContext, uiComponent); |
105 | 0 | writer.writeAttribute(HTML.VALUE_ATTR, strValue, JSFAttr.VALUE_ATTR); |
106 | |
} |
107 | |
|
108 | 0 | Map<String, List<ClientBehavior>> behaviors = null; |
109 | 0 | if (uiComponent instanceof ClientBehaviorHolder) |
110 | |
{ |
111 | 0 | behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors(); |
112 | |
|
113 | 0 | long commonPropertiesMarked = 0L; |
114 | 0 | if (isCommonPropertiesOptimizationEnabled(facesContext)) |
115 | |
{ |
116 | 0 | commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(uiComponent); |
117 | |
} |
118 | 0 | if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) |
119 | |
{ |
120 | 0 | CommonPropertyUtils.renderChangeEventProperty(writer, |
121 | |
commonPropertiesMarked, uiComponent); |
122 | 0 | CommonPropertyUtils.renderEventProperties(writer, |
123 | |
commonPropertiesMarked, uiComponent); |
124 | 0 | CommonPropertyUtils.renderFieldEventPropertiesWithoutOnchange(writer, |
125 | |
commonPropertiesMarked, uiComponent); |
126 | |
} |
127 | |
else |
128 | |
{ |
129 | 0 | HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors); |
130 | 0 | if (isCommonEventsOptimizationEnabled(facesContext)) |
131 | |
{ |
132 | 0 | Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(uiComponent); |
133 | 0 | CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, |
134 | |
commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors); |
135 | 0 | CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange( |
136 | |
facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors); |
137 | 0 | } |
138 | |
else |
139 | |
{ |
140 | 0 | HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors); |
141 | 0 | HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange( |
142 | |
facesContext, writer, uiComponent, behaviors); |
143 | |
} |
144 | |
} |
145 | 0 | if (isCommonPropertiesOptimizationEnabled(facesContext)) |
146 | |
{ |
147 | 0 | CommonPropertyUtils.renderInputPassthroughPropertiesWithoutDisabledAndEvents(writer, |
148 | |
commonPropertiesMarked, uiComponent); |
149 | |
} |
150 | |
else |
151 | |
{ |
152 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, |
153 | |
HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS); |
154 | |
} |
155 | 0 | } |
156 | |
else |
157 | |
{ |
158 | 0 | if (isCommonPropertiesOptimizationEnabled(facesContext)) |
159 | |
{ |
160 | 0 | CommonPropertyUtils.renderInputPassthroughPropertiesWithoutDisabled(writer, |
161 | |
CommonPropertyUtils.getCommonPropertiesMarked(uiComponent), uiComponent); |
162 | |
} |
163 | |
else |
164 | |
{ |
165 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, |
166 | |
HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED); |
167 | |
} |
168 | |
} |
169 | |
|
170 | 0 | if (isDisabled(facesContext, uiComponent)) |
171 | |
{ |
172 | 0 | writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null); |
173 | |
} |
174 | |
|
175 | 0 | if (isAutocompleteOff(facesContext, uiComponent)) |
176 | |
{ |
177 | 0 | writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR); |
178 | |
} |
179 | 0 | } |
180 | |
|
181 | |
protected void renderInputEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException |
182 | |
{ |
183 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
184 | |
|
185 | 0 | writer.endElement(HTML.INPUT_ELEM); |
186 | 0 | } |
187 | |
|
188 | |
protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) |
189 | |
{ |
190 | |
|
191 | 0 | if (uiComponent instanceof HtmlInputSecret) |
192 | |
{ |
193 | 0 | return ((HtmlInputSecret)uiComponent).isDisabled(); |
194 | |
} |
195 | |
|
196 | 0 | return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
protected boolean isAutocompleteOff(FacesContext facesContext, UIComponent component) |
203 | |
{ |
204 | 0 | if (component instanceof HtmlInputSecret) |
205 | |
{ |
206 | 0 | String autocomplete = ((HtmlInputSecret)component).getAutocomplete(); |
207 | 0 | if (autocomplete != null) |
208 | |
{ |
209 | 0 | return autocomplete.equals(AUTOCOMPLETE_VALUE_OFF); |
210 | |
} |
211 | |
} |
212 | |
|
213 | 0 | return false; |
214 | |
} |
215 | |
|
216 | |
public void decode(FacesContext facesContext, UIComponent component) |
217 | |
{ |
218 | 0 | org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, component, UIInput.class); |
219 | 0 | HtmlRendererUtils.decodeUIInput(facesContext, component); |
220 | 0 | if (component instanceof ClientBehaviorHolder && |
221 | |
!HtmlRendererUtils.isDisabled(component)) |
222 | |
{ |
223 | 0 | HtmlRendererUtils.decodeClientBehaviors(facesContext, component); |
224 | |
} |
225 | 0 | } |
226 | |
|
227 | |
public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) |
228 | |
throws ConverterException |
229 | |
{ |
230 | 0 | RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class); |
231 | 0 | return RendererUtils.getConvertedUIOutputValue(facesContext, |
232 | |
(UIOutput)uiComponent, |
233 | |
submittedValue); |
234 | |
} |
235 | |
|
236 | |
} |