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 | |
import java.util.Iterator; |
20 | |
|
21 | |
import javax.faces.application.FacesMessage; |
22 | |
import javax.faces.component.UIComponent; |
23 | |
import javax.faces.component.html.HtmlMessages; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.context.ResponseWriter; |
26 | |
|
27 | |
import org.seasar.teeda.core.JsfConstants; |
28 | |
import org.seasar.teeda.core.util.RendererUtil; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 55 | public class HtmlMessagesRenderer extends AbstractHtmlMessagesRenderer { |
34 | |
|
35 | |
public static final String COMPONENT_FAMILY = "javax.faces.Messages"; |
36 | |
|
37 | |
public static final String RENDERER_TYPE = "javax.faces.Messages"; |
38 | |
|
39 | |
public void encodeEnd(FacesContext context, UIComponent component) |
40 | |
throws IOException { |
41 | 32 | assertNotNull(context, component); |
42 | 30 | if (!component.isRendered()) { |
43 | 1 | return; |
44 | |
} |
45 | 29 | encodeHtmlMessagesEnd(context, (HtmlMessages) component); |
46 | 29 | } |
47 | |
|
48 | |
protected void encodeHtmlMessagesEnd(FacesContext context, |
49 | |
HtmlMessages htmlMessages) throws IOException { |
50 | 29 | ResponseWriter writer = context.getResponseWriter(); |
51 | |
Iterator it; |
52 | 29 | if (htmlMessages.isGlobalOnly()) { |
53 | 1 | it = context.getMessages(null); |
54 | |
} else { |
55 | 28 | it = context.getMessages(); |
56 | |
} |
57 | 29 | if (!it.hasNext()) { |
58 | 1 | return; |
59 | |
} |
60 | 28 | final boolean tableLayout = isTableLayout(htmlMessages); |
61 | |
|
62 | 28 | if (tableLayout) { |
63 | 5 | writer.startElement(JsfConstants.TABLE_ELEM, htmlMessages); |
64 | |
} else { |
65 | 23 | writer.startElement(JsfConstants.UL_ELEM, htmlMessages); |
66 | |
} |
67 | 28 | RendererUtil.renderIdAttributeIfNecessary(writer, htmlMessages, |
68 | |
getIdForRender(context, htmlMessages)); |
69 | 59 | while (it.hasNext()) { |
70 | 31 | if (tableLayout) { |
71 | 7 | writer.startElement(JsfConstants.TR_ELEM, htmlMessages); |
72 | 7 | writer.startElement(JsfConstants.TD_ELEM, htmlMessages); |
73 | |
} else { |
74 | 24 | writer.startElement(JsfConstants.LI_ELEM, htmlMessages); |
75 | |
} |
76 | 31 | FacesMessage facesMassage = (FacesMessage) it.next(); |
77 | 31 | renderOneMessage(context, htmlMessages, facesMassage, null, |
78 | |
htmlMessages.getAttributes()); |
79 | 31 | if (tableLayout) { |
80 | 7 | writer.endElement(JsfConstants.TD_ELEM); |
81 | 7 | writer.endElement(JsfConstants.TR_ELEM); |
82 | |
} else { |
83 | 24 | writer.endElement(JsfConstants.LI_ELEM); |
84 | |
} |
85 | |
} |
86 | 28 | if (tableLayout) { |
87 | 5 | writer.endElement(JsfConstants.TABLE_ELEM); |
88 | |
} else { |
89 | 23 | writer.endElement(JsfConstants.UL_ELEM); |
90 | |
} |
91 | 28 | } |
92 | |
|
93 | |
protected boolean isTableLayout(HtmlMessages htmlMessages) { |
94 | 28 | return JsfConstants.TABLE_VALUE.equals(htmlMessages.getLayout()); |
95 | |
} |
96 | |
|
97 | |
} |