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.HtmlOutputLabel; |
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.AbstractRenderer; |
28 | |
import org.seasar.teeda.core.util.RendererUtil; |
29 | |
import org.seasar.teeda.core.util.ValueHolderUtil; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | 36 | public class HtmlOutputLabelRenderer extends AbstractRenderer { |
35 | |
|
36 | |
public static final String COMPONENT_FAMILY = "javax.faces.Output"; |
37 | |
|
38 | |
public static final String RENDERER_TYPE = "javax.faces.Label"; |
39 | |
|
40 | 36 | private final IgnoreAttribute ignoreComponent = new IgnoreAttribute(); |
41 | |
{ |
42 | 36 | ignoreComponent.addAttributeName(JsfConstants.ID_ATTR); |
43 | 36 | ignoreComponent.addAttributeName(JsfConstants.VALUE_ATTR); |
44 | 36 | ignoreComponent.addAttributeName(JsfConstants.FOR_ATTR); |
45 | 36 | } |
46 | |
|
47 | |
public void encodeBegin(final FacesContext context, |
48 | |
final UIComponent component) throws IOException { |
49 | 12 | assertNotNull(context, component); |
50 | 10 | if (!component.isRendered()) { |
51 | 1 | return; |
52 | |
} |
53 | 9 | encodeHtmlOutputLabelBegin(context, (HtmlOutputLabel) component); |
54 | 8 | } |
55 | |
|
56 | |
protected void encodeHtmlOutputLabelBegin(final FacesContext context, |
57 | |
final HtmlOutputLabel htmlOutputLabel) throws IOException { |
58 | 9 | final ResponseWriter writer = context.getResponseWriter(); |
59 | |
|
60 | 9 | writer.startElement(JsfConstants.LABEL_ELEM, htmlOutputLabel); |
61 | 9 | RendererUtil.renderIdAttributeIfNecessary(writer, htmlOutputLabel, |
62 | |
getIdForRender(context, htmlOutputLabel)); |
63 | |
|
64 | 9 | final String forAttr = htmlOutputLabel.getFor(); |
65 | 9 | if (forAttr != null) { |
66 | 3 | final UIComponent forComponent = htmlOutputLabel |
67 | |
.findComponent(forAttr); |
68 | 3 | if (forComponent == null) { |
69 | 1 | throw new IllegalStateException("for Component [" + forAttr |
70 | |
+ "] does not found"); |
71 | |
} |
72 | 2 | final String forClientId = getIdForRender(context, forComponent); |
73 | 2 | RendererUtil.renderAttribute(writer, JsfConstants.FOR_ATTR, |
74 | |
forClientId, null); |
75 | |
} |
76 | 8 | renderRemainAttributes(htmlOutputLabel, writer, ignoreComponent); |
77 | 8 | final String value = ValueHolderUtil.getValueForRender(context, |
78 | |
htmlOutputLabel); |
79 | 8 | writer.writeText(value, null); |
80 | 8 | } |
81 | |
|
82 | |
public void encodeEnd(final FacesContext context, |
83 | |
final UIComponent component) throws IOException { |
84 | 5 | assertNotNull(context, component); |
85 | 3 | if (!component.isRendered()) { |
86 | 1 | return; |
87 | |
} |
88 | 2 | encodeHtmlOutputLabelEnd(context, (HtmlOutputLabel) component); |
89 | 2 | } |
90 | |
|
91 | |
protected void encodeHtmlOutputLabelEnd(final FacesContext context, |
92 | |
final HtmlOutputLabel htmlOutputLabel) throws IOException { |
93 | 2 | final ResponseWriter writer = context.getResponseWriter(); |
94 | 2 | writer.endElement(JsfConstants.LABEL_ELEM); |
95 | 2 | } |
96 | |
|
97 | |
} |