示例#1
0
  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("&times;");
    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");
  }
  private void log4j(FacesMessage message, final StringBuilder msgBuilder) {

    final Severity severity = message.getSeverity();
    if (FacesMessage.SEVERITY_INFO.equals(severity)) {
      log.info(msgBuilder.toString());
    } else if (FacesMessage.SEVERITY_WARN.equals(severity)) {
      log.warn(msgBuilder.toString());
    } else if (FacesMessage.SEVERITY_ERROR.equals(severity)) {
      log.error(msgBuilder.toString());
    } else if (FacesMessage.SEVERITY_FATAL.equals(severity)) {
      //			log.fatal(message.getSummary());
      log.error(msgBuilder.toString());
    }
  }