Ejemplo n.º 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");
  }
Ejemplo n.º 2
0
  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());
    }
  }
  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;
  }