1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.render.html; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
|
20 | |
import javax.faces.component.UIComponent; |
21 | |
import javax.faces.component.html.HtmlInputText; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
import javax.faces.context.ResponseWriter; |
24 | |
import javax.faces.internal.IgnoreAttribute; |
25 | |
|
26 | |
import org.seasar.teeda.core.JsfConstants; |
27 | |
import org.seasar.teeda.core.render.AbstractInputRenderer; |
28 | |
import org.seasar.teeda.core.util.HTMLEncodeUtil; |
29 | |
import org.seasar.teeda.core.util.RendererUtil; |
30 | |
import org.seasar.teeda.core.util.ValueHolderUtil; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 39 | public class HtmlInputTextRenderer extends AbstractInputRenderer { |
36 | |
|
37 | |
public static final String COMPONENT_FAMILY = "javax.faces.Input"; |
38 | |
|
39 | |
public static final String RENDERER_TYPE = "javax.faces.Text"; |
40 | |
|
41 | 39 | private final IgnoreAttribute ignoreComponent = new IgnoreAttribute(); |
42 | |
{ |
43 | 39 | ignoreComponent.addAttributeName(JsfConstants.ID_ATTR); |
44 | 39 | ignoreComponent.addAttributeName(JsfConstants.NAME_ATTR); |
45 | 39 | ignoreComponent.addAttributeName(JsfConstants.TYPE_ATTR); |
46 | 39 | ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR); |
47 | 39 | ignoreComponent.addAttributeName(JsfConstants.STYLE_CLASS_ATTR); |
48 | 39 | ignoreComponent.addAttributeName(JsfConstants.AUTOCOMPLETE_ATTR); |
49 | 39 | } |
50 | |
|
51 | |
public void encodeEnd(FacesContext context, UIComponent component) |
52 | |
throws IOException { |
53 | 12 | assertNotNull(context, component); |
54 | 10 | if (!component.isRendered()) { |
55 | 1 | return; |
56 | |
} |
57 | 9 | encodeHtmlInputTextEnd(context, (HtmlInputText) component); |
58 | 9 | } |
59 | |
|
60 | |
protected void encodeHtmlInputTextEnd(FacesContext context, |
61 | |
HtmlInputText htmlInputText) throws IOException { |
62 | 9 | ResponseWriter writer = context.getResponseWriter(); |
63 | 9 | writer.startElement(JsfConstants.INPUT_ELEM, htmlInputText); |
64 | 9 | RendererUtil.renderAttribute(writer, JsfConstants.TYPE_ATTR, |
65 | |
JsfConstants.TEXT_VALUE); |
66 | 9 | RendererUtil.renderIdAttributeIfNecessary(writer, htmlInputText, |
67 | |
getIdForRender(context, htmlInputText)); |
68 | 9 | RendererUtil.renderAttribute(writer, JsfConstants.NAME_ATTR, |
69 | |
htmlInputText.getClientId(context)); |
70 | 9 | String value = ValueHolderUtil |
71 | |
.getValueForRender(context, htmlInputText); |
72 | 9 | RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, |
73 | |
HTMLEncodeUtil.encode(value, true, true)); |
74 | 9 | RendererUtil.renderAttribute(writer, JsfConstants.AUTOCOMPLETE_ATTR, |
75 | |
htmlInputText.getAutocomplete()); |
76 | 9 | renderStyleClass(context, htmlInputText, writer); |
77 | 9 | renderRemainAttributes(htmlInputText, writer, ignoreComponent); |
78 | 9 | writer.endElement(JsfConstants.INPUT_ELEM); |
79 | 9 | } |
80 | |
|
81 | |
protected void renderStyleClass(FacesContext context, |
82 | |
HtmlInputText htmlInputText, ResponseWriter writer) |
83 | |
throws IOException { |
84 | 9 | final String styleClass = htmlInputText.getStyleClass(); |
85 | 9 | RendererUtil.renderAttribute(writer, JsfConstants.STYLE_CLASS_ATTR, |
86 | |
styleClass); |
87 | 9 | } |
88 | |
|
89 | |
public void decode(FacesContext context, UIComponent component) { |
90 | 5 | assertNotNull(context, component); |
91 | 3 | decodeHtmlInputText(context, (HtmlInputText) component); |
92 | 3 | } |
93 | |
|
94 | |
protected void decodeHtmlInputText(FacesContext context, |
95 | |
HtmlInputText htmlInputText) { |
96 | 3 | getDecoder().decode(context, htmlInputText); |
97 | 3 | } |
98 | |
|
99 | |
public void addIgnoreAttributeName(final String name) { |
100 | 0 | ignoreComponent.addAttributeName(name); |
101 | 0 | } |
102 | |
|
103 | |
public IgnoreAttribute getIgnoreAttributes() { |
104 | 0 | return ignoreComponent; |
105 | |
} |
106 | |
|
107 | |
} |