1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.shared_impl.renderkit.html; |
20 | |
|
21 | |
import org.apache.myfaces.shared_impl.renderkit.JSFAttr; |
22 | |
import org.apache.myfaces.shared_impl.renderkit.RendererUtils; |
23 | |
|
24 | |
import javax.faces.component.UIComponent; |
25 | |
import javax.faces.component.UIInput; |
26 | |
import javax.faces.component.UIOutput; |
27 | |
import javax.faces.component.html.HtmlInputSecret; |
28 | |
import javax.faces.context.FacesContext; |
29 | |
import javax.faces.context.ResponseWriter; |
30 | |
import javax.faces.convert.ConverterException; |
31 | |
import java.io.IOException; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class HtmlSecretRendererBase |
42 | |
extends HtmlRenderer |
43 | |
{ |
44 | |
private static final String AUTOCOMPLETE_VALUE_OFF = "off"; |
45 | |
|
46 | |
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) |
47 | |
throws IOException |
48 | |
{ |
49 | 0 | RendererUtils.checkParamValidity(facesContext, uiComponent, UIInput.class); |
50 | |
|
51 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
52 | 0 | writer.startElement(HTML.INPUT_ELEM, uiComponent); |
53 | 0 | writer.writeAttribute(HTML.TYPE_ATTR, org.apache.myfaces.shared_impl.renderkit.html.HTML.INPUT_TYPE_PASSWORD, null); |
54 | |
|
55 | 0 | String clientId = uiComponent.getClientId(facesContext); |
56 | |
|
57 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext); |
58 | 0 | writer.writeAttribute(HTML.NAME_ATTR, clientId, null); |
59 | |
|
60 | |
boolean isRedisplay; |
61 | 0 | if (uiComponent instanceof HtmlInputSecret) |
62 | |
{ |
63 | 0 | isRedisplay = ((HtmlInputSecret)uiComponent).isRedisplay(); |
64 | |
} |
65 | |
else |
66 | |
{ |
67 | 0 | isRedisplay = org.apache.myfaces.shared_impl.renderkit.RendererUtils.getBooleanAttribute(uiComponent, JSFAttr.REDISPLAY_ATTR, false); |
68 | |
} |
69 | 0 | if (isRedisplay) |
70 | |
{ |
71 | 0 | String strValue = RendererUtils.getStringValue(facesContext, uiComponent); |
72 | 0 | writer.writeAttribute(HTML.VALUE_ATTR, strValue, JSFAttr.VALUE_ATTR); |
73 | |
} |
74 | |
|
75 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED); |
76 | 0 | if (isDisabled(facesContext, uiComponent)) |
77 | |
{ |
78 | 0 | writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null); |
79 | |
} |
80 | |
|
81 | 0 | if (isAutocompleteOff(facesContext, uiComponent)) |
82 | |
{ |
83 | 0 | writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR); |
84 | |
} |
85 | |
|
86 | 0 | writer.endElement(HTML.INPUT_ELEM); |
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) |
91 | |
{ |
92 | |
|
93 | 0 | if (uiComponent instanceof HtmlInputSecret) |
94 | |
{ |
95 | 0 | return ((HtmlInputSecret)uiComponent).isDisabled(); |
96 | |
} |
97 | |
|
98 | 0 | return RendererUtils.getBooleanAttribute(uiComponent, HTML.DISABLED_ATTR, false); |
99 | |
} |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
protected boolean isAutocompleteOff(FacesContext facesContext, UIComponent component) |
105 | |
{ |
106 | 0 | if (component instanceof HtmlInputSecret) |
107 | |
{ |
108 | 0 | String autocomplete = ((HtmlInputSecret)component).getAutocomplete(); |
109 | 0 | if (autocomplete != null) |
110 | |
{ |
111 | 0 | return autocomplete.equals(AUTOCOMPLETE_VALUE_OFF); |
112 | |
} |
113 | |
} |
114 | |
|
115 | 0 | return false; |
116 | |
} |
117 | |
|
118 | |
public void decode(FacesContext facesContext, UIComponent component) |
119 | |
{ |
120 | 0 | org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, component, UIInput.class); |
121 | 0 | HtmlRendererUtils.decodeUIInput(facesContext, component); |
122 | 0 | } |
123 | |
|
124 | |
public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException |
125 | |
{ |
126 | 0 | RendererUtils.checkParamValidity(facesContext, uiComponent, UIOutput.class); |
127 | 0 | return RendererUtils.getConvertedUIOutputValue(facesContext, |
128 | |
(UIOutput)uiComponent, |
129 | |
submittedValue); |
130 | |
} |
131 | |
|
132 | |
} |