/** * Encode the case when the <code>var</code> attribute is specified. This will render without any * HTML markup and put the current message in the request scope as identified by the <code>var * </code> attribute. Note: the iteration is by design completely stateless. * * @param context The involved faces context. * @param component The messages component. * @param messages The queued faces messages. * @throws IOException When an I/O error occurs. */ protected void encodeMessagesRepeater( FacesContext context, OmniMessages component, List<FacesMessage> messages) throws IOException { String var = component.getVar(); Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); Object originalVar = requestMap.get(var); try { for (FacesMessage message : messages) { if (message.isRendered() && !component.isRedisplay()) { continue; } requestMap.put(var, message); for (UIComponent child : component.getChildren()) { child.encodeAll(context); } message.rendered(); } } finally { if (originalVar != null) { requestMap.put(var, originalVar); } else { requestMap.remove(var); } } }
private void encodeSeverityMessages( FacesContext facesContext, UIComponent component, UIMessages uiMessages, Severity severity, List<FacesMessage> messages) throws IOException { ResponseWriter writer = facesContext.getResponseWriter(); String alertSeverityClass = ""; if (FacesMessage.SEVERITY_INFO.equals(severity)) { alertSeverityClass = "alert-info"; } else if (FacesMessage.SEVERITY_WARN.equals(severity)) { alertSeverityClass = ""; // Default alert is a warning } else if (FacesMessage.SEVERITY_ERROR.equals(severity)) { alertSeverityClass = "alert-error"; } else if (FacesMessage.SEVERITY_FATAL.equals(severity)) { alertSeverityClass = "alert-error"; } writer.startElement("div", null); writer.writeAttribute("class", "alert " + alertSeverityClass, "alert " + alertSeverityClass); writer.startElement("a", component); writer.writeAttribute("class", "close", "class"); writer.writeAttribute("data-dismiss", "alert", "data-dismiss"); writer.writeAttribute("href", "#", "href"); writer.write("×"); writer.endElement("a"); writer.startElement("ul", null); for (FacesMessage msg : messages) { String summary = msg.getSummary() != null ? msg.getSummary() : ""; String detail = msg.getDetail() != null ? msg.getDetail() : summary; writer.startElement("li", component); if (uiMessages.isShowSummary()) { writer.startElement("strong", component); writer.writeText(summary, component, null); writer.endElement("strong"); } if (uiMessages.isShowDetail()) { writer.writeText(" " + detail, null); } writer.endElement("li"); msg.rendered(); } writer.endElement("ul"); writer.endElement("div"); }
/** * Encode the case when the faces messages are to be rendered as either a HTML table or a HTML * list. * * @param context The involved faces context. * @param component The messages component. * @param messages The queued faces messages. * @param table Whether to render the messages as a HTML table or a HTML list. * @throws IOException When an I/O error occurs. */ protected void encodeMessages( FacesContext context, OmniMessages component, List<FacesMessage> messages, boolean table) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement(table ? "table" : "ul", component); writeAttribute(writer, "id", component.getClientId(context)); writeAttribute(writer, component, "styleClass", "class"); writeAttributes(writer, component, "style", "title", "lang", "dir"); boolean showSummary = component.isShowSummary(); boolean showDetail = component.isShowDetail(); boolean escape = component.isEscape(); boolean tooltip = component.isTooltip() && isEmpty(component.getTitle()); for (FacesMessage message : messages) { if (!message.isRendered() || component.isRedisplay()) { encodeMessage(context, component, message, table, showSummary, showDetail, escape, tooltip); message.rendered(); } } writer.endElement(table ? "table" : "ul"); }
private List<FacesMessage> convertToFacesMsgs(List<BridgeMessage> list) { List<FacesMessage> facesMsgs = new ArrayList<FacesMessage>(list.size()); for (BridgeMessage msg : list) { FacesMessage facesMsg = new FacesMessage(msg.summary, msg.detail); if (msg.rendered) { facesMsg.rendered(); } int ordinal = msg.severityOrdinal; if (ordinal == FacesMessage.SEVERITY_INFO.getOrdinal()) { facesMsg.setSeverity(FacesMessage.SEVERITY_INFO); } else if (ordinal == FacesMessage.SEVERITY_WARN.getOrdinal()) { facesMsg.setSeverity(FacesMessage.SEVERITY_WARN); } else if (ordinal == FacesMessage.SEVERITY_ERROR.getOrdinal()) { facesMsg.setSeverity(FacesMessage.SEVERITY_ERROR); } else if (ordinal == FacesMessage.SEVERITY_FATAL.getOrdinal()) { facesMsg.setSeverity(FacesMessage.SEVERITY_FATAL); } facesMsgs.add(facesMsg); } return facesMsgs; }