| 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.FacesException; |
| 22 | |
import javax.faces.application.FacesMessage; |
| 23 | |
import javax.faces.component.UIComponent; |
| 24 | |
import javax.faces.component.html.HtmlMessage; |
| 25 | |
import javax.faces.context.FacesContext; |
| 26 | |
|
| 27 | |
import org.seasar.framework.log.Logger; |
| 28 | |
import org.seasar.teeda.core.util.RendererUtil; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 51 | public class HtmlMessageRenderer extends AbstractHtmlMessagesRenderer { |
| 34 | |
|
| 35 | |
public static final String COMPONENT_FAMILY = "javax.faces.Message"; |
| 36 | |
|
| 37 | |
public static final String RENDERER_TYPE = "javax.faces.Message"; |
| 38 | |
|
| 39 | 1 | private static final Logger logger = Logger |
| 40 | 1 | .getLogger(HtmlMessageRenderer.class); |
| 41 | |
|
| 42 | |
public void encodeEnd(FacesContext context, UIComponent component) |
| 43 | |
throws IOException { |
| 44 | 28 | assertNotNull(context, component); |
| 45 | 26 | if (!component.isRendered()) { |
| 46 | 1 | return; |
| 47 | |
} |
| 48 | 25 | encodeHtmlMessageEnd(context, (HtmlMessage) component); |
| 49 | 24 | } |
| 50 | |
|
| 51 | |
protected void encodeHtmlMessageEnd(FacesContext context, |
| 52 | |
HtmlMessage htmlMessage) throws IOException { |
| 53 | 25 | String forAttr = htmlMessage.getFor(); |
| 54 | 25 | if (forAttr == null) { |
| 55 | 1 | throw new FacesException("for"); |
| 56 | |
} |
| 57 | 24 | UIComponent forComponent = htmlMessage.findComponent(forAttr); |
| 58 | 24 | if (forComponent == null) { |
| 59 | 1 | logger.debug("[HtmlMessage] forComponent [" + forAttr |
| 60 | |
+ "] is null. [id=" + htmlMessage.getId() + "]"); |
| 61 | 1 | return; |
| 62 | |
} |
| 63 | 23 | final String clientId = forComponent.getClientId(context); |
| 64 | 23 | Iterator it = context.getMessages(clientId); |
| 65 | 23 | if (!it.hasNext()) { |
| 66 | 1 | return; |
| 67 | |
} |
| 68 | |
|
| 69 | 22 | FacesMessage facesMassage = (FacesMessage) it.next(); |
| 70 | 22 | String idForRender = getIdForRenderOrNull(context, htmlMessage); |
| 71 | 22 | renderOneMessage(context, htmlMessage, facesMassage, idForRender, |
| 72 | |
htmlMessage.getAttributes()); |
| 73 | 22 | } |
| 74 | |
|
| 75 | |
private String getIdForRenderOrNull(FacesContext context, |
| 76 | |
HtmlMessage htmlMessage) { |
| 77 | 22 | if (RendererUtil.shouldRenderIdAttribute(htmlMessage)) { |
| 78 | 1 | return getIdForRender(context, htmlMessage); |
| 79 | |
} |
| 80 | 21 | return null; |
| 81 | |
} |
| 82 | |
|
| 83 | |
} |