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.commons.logging.Log; |
22 | |
import org.apache.commons.logging.LogFactory; |
23 | |
import org.apache.myfaces.shared_impl.component.EscapeCapable; |
24 | |
import org.apache.myfaces.shared_impl.renderkit.JSFAttr; |
25 | |
import org.apache.myfaces.shared_impl.renderkit.RendererUtils; |
26 | |
|
27 | |
import javax.faces.component.UIComponent; |
28 | |
import javax.faces.component.UIInput; |
29 | |
import javax.faces.component.UIOutput; |
30 | |
import javax.faces.component.UIViewRoot; |
31 | |
import javax.faces.component.html.HtmlInputText; |
32 | |
import javax.faces.component.html.HtmlOutputText; |
33 | |
import javax.faces.context.FacesContext; |
34 | |
import javax.faces.context.ResponseWriter; |
35 | |
import javax.faces.convert.ConverterException; |
36 | |
import java.io.IOException; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class HtmlTextRendererBase |
44 | |
extends HtmlRenderer |
45 | |
{ |
46 | 0 | private static final Log log = LogFactory.getLog(HtmlTextRendererBase.class); |
47 | |
|
48 | |
private static final String AUTOCOMPLETE_VALUE_OFF = "off"; |
49 | |
|
50 | |
public void encodeEnd(FacesContext facesContext, UIComponent component) |
51 | |
throws IOException |
52 | |
{ |
53 | 0 | org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext,component,null); |
54 | |
|
55 | 0 | if (component instanceof UIInput) |
56 | |
{ |
57 | 0 | renderInput(facesContext, component); |
58 | |
} |
59 | 0 | else if (component instanceof UIOutput) |
60 | |
{ |
61 | 0 | renderOutput(facesContext, component); |
62 | |
} |
63 | |
else |
64 | |
{ |
65 | 0 | throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName()); |
66 | |
} |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
protected static void renderOutput(FacesContext facesContext, UIComponent component) |
71 | |
throws IOException |
72 | |
{ |
73 | |
|
74 | 0 | String text = org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(facesContext, component); |
75 | 0 | if (log.isDebugEnabled()) log.debug("renderOutput '" + text + "'"); |
76 | |
boolean escape; |
77 | 0 | if (component instanceof HtmlOutputText || component instanceof EscapeCapable) |
78 | |
{ |
79 | 0 | escape = ((HtmlOutputText)component).isEscape(); |
80 | |
} |
81 | |
else |
82 | |
{ |
83 | 0 | escape = RendererUtils.getBooleanAttribute(component, org.apache.myfaces.shared_impl.renderkit.JSFAttr.ESCAPE_ATTR, |
84 | |
true); |
85 | |
} |
86 | 0 | renderOutputText(facesContext, component, text, escape); |
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
public static void renderOutputText(FacesContext facesContext, |
91 | |
UIComponent component, |
92 | |
String text, |
93 | |
boolean escape) |
94 | |
throws IOException |
95 | |
{ |
96 | 0 | if (text != null) |
97 | |
{ |
98 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
99 | 0 | boolean span = false; |
100 | |
|
101 | 0 | if(component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) |
102 | |
{ |
103 | 0 | span = true; |
104 | |
|
105 | 0 | writer.startElement(HTML.SPAN_ELEM, component); |
106 | |
|
107 | 0 | HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext); |
108 | |
|
109 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.COMMON_PASSTROUGH_ATTRIBUTES); |
110 | |
|
111 | |
} |
112 | |
else |
113 | |
{ |
114 | 0 | span = HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,component, |
115 | |
HTML.SPAN_ELEM,HTML.COMMON_PASSTROUGH_ATTRIBUTES); |
116 | |
} |
117 | |
|
118 | 0 | if (escape) |
119 | |
{ |
120 | 0 | if (log.isDebugEnabled()) log.debug("renderOutputText writing '" + text + "'"); |
121 | 0 | writer.writeText(text, org.apache.myfaces.shared_impl.renderkit.JSFAttr.VALUE_ATTR); |
122 | |
} |
123 | |
else |
124 | |
{ |
125 | 0 | writer.write(text); |
126 | |
} |
127 | |
|
128 | 0 | if(span) |
129 | |
{ |
130 | 0 | writer.endElement(org.apache.myfaces.shared_impl.renderkit.html.HTML.SPAN_ELEM); |
131 | |
} |
132 | |
} |
133 | 0 | } |
134 | |
|
135 | |
|
136 | |
protected void renderInput(FacesContext facesContext, UIComponent component) |
137 | |
throws IOException |
138 | |
{ |
139 | 0 | ResponseWriter writer = facesContext.getResponseWriter(); |
140 | |
|
141 | 0 | String clientId = component.getClientId(facesContext); |
142 | 0 | String value = org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(facesContext, component); |
143 | 0 | if (log.isDebugEnabled()) log.debug("renderInput '" + value + "'"); |
144 | 0 | writer.startElement(HTML.INPUT_ELEM, component); |
145 | 0 | writer.writeAttribute(HTML.ID_ATTR, clientId, null); |
146 | 0 | writer.writeAttribute(HTML.NAME_ATTR, clientId, null); |
147 | 0 | writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_TEXT, null); |
148 | 0 | if (value != null) |
149 | |
{ |
150 | 0 | writer.writeAttribute(HTML.VALUE_ATTR, value, JSFAttr.VALUE_ATTR); |
151 | |
} |
152 | |
|
153 | 0 | HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED); |
154 | 0 | if (isDisabled(facesContext, component)) |
155 | |
{ |
156 | 0 | writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null); |
157 | |
} |
158 | |
|
159 | 0 | if (isAutocompleteOff(facesContext, component)) |
160 | |
{ |
161 | 0 | writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR); |
162 | |
} |
163 | |
|
164 | 0 | writer.endElement(HTML.INPUT_ELEM); |
165 | 0 | } |
166 | |
|
167 | |
protected boolean isDisabled(FacesContext facesContext, UIComponent component) |
168 | |
{ |
169 | |
|
170 | 0 | if (component instanceof HtmlInputText) |
171 | |
{ |
172 | 0 | return ((HtmlInputText)component).isDisabled(); |
173 | |
} |
174 | |
|
175 | 0 | return org.apache.myfaces.shared_impl.renderkit.RendererUtils.getBooleanAttribute(component, HTML.DISABLED_ATTR, false); |
176 | |
|
177 | |
} |
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
protected boolean isAutocompleteOff(FacesContext facesContext, UIComponent component) |
183 | |
{ |
184 | 0 | if (component instanceof HtmlInputText) |
185 | |
{ |
186 | 0 | String autocomplete = ((HtmlInputText)component).getAutocomplete(); |
187 | 0 | if (autocomplete != null) |
188 | |
{ |
189 | 0 | return autocomplete.equals(AUTOCOMPLETE_VALUE_OFF); |
190 | |
} |
191 | |
} |
192 | |
|
193 | 0 | return false; |
194 | |
} |
195 | |
|
196 | |
|
197 | |
public void decode(FacesContext facesContext, UIComponent component) |
198 | |
{ |
199 | 0 | RendererUtils.checkParamValidity(facesContext,component,null); |
200 | |
|
201 | 0 | if (component instanceof UIInput) |
202 | |
{ |
203 | 0 | HtmlRendererUtils.decodeUIInput(facesContext, component); |
204 | |
} |
205 | 0 | else if (component instanceof UIOutput) |
206 | |
{ |
207 | |
|
208 | |
} |
209 | |
else |
210 | |
{ |
211 | 0 | throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName()); |
212 | |
} |
213 | 0 | } |
214 | |
|
215 | |
|
216 | |
public Object getConvertedValue(FacesContext facesContext, UIComponent component, Object submittedValue) throws ConverterException |
217 | |
{ |
218 | 0 | org.apache.myfaces.shared_impl.renderkit.RendererUtils.checkParamValidity(facesContext, component, UIOutput.class); |
219 | 0 | return RendererUtils.getConvertedUIOutputValue(facesContext, |
220 | |
(UIOutput)component, |
221 | |
submittedValue); |
222 | |
} |
223 | |
|
224 | |
} |