Beispiel #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 BridgeMessage convertToBridgeMsg(FacesMessage message) {
   BridgeMessage bridgeMsg = new BridgeMessage();
   bridgeMsg.detail = message.getDetail();
   bridgeMsg.summary = message.getSummary();
   bridgeMsg.rendered = message.isRendered();
   bridgeMsg.severityOrdinal = message.getSeverity().getOrdinal();
   return bridgeMsg;
 }
  @Override
  protected Object[] getJsValidatorParametersAsString(FacesContext context, UIComponent component) {
    Object[] args = {component.getId()};
    FacesMessage message =
        MessageUtil.getMessage(
            context, FacesMessage.SEVERITY_ERROR, UIInput.REQUIRED_MESSAGE_ID, args);

    return new String[] {message.getSummary(), message.getDetail()};
  }
  @Observer("org.jboss.seam.validationFailed")
  public void observeFailedValidation() {
    log.info("validation of JSF component failed");
    Iterator<FacesMessage> it = FacesContext.getCurrentInstance().getMessages();

    while (it.hasNext()) {
      FacesMessage fm = it.next();
      log.info("Found FacesMessage: #0 #1 #2", fm.getSeverity(), fm.getSummary(), fm.getDetail());
    }
  }
Beispiel #5
0
  private void logMessages(FacesContext context) {
    UIViewRoot root = context.getViewRoot();
    String viewId = "";

    if (root != null) viewId = root.getViewId();

    Iterator<FacesMessage> iter = context.getMessages();

    while (iter != null && iter.hasNext()) {
      FacesMessage msg = iter.next();

      if (log.isLoggable(Level.FINE)) {
        if (msg.getDetail() != null)
          log.fine(
              viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary() + " " + msg.getDetail());
        else log.fine(viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary());
      }
    }
  }
Beispiel #6
0
 public AppFacesException(String messageCode, Object[] args, Throwable cause) {
   super(cause);
   final FacesContext context = FacesContext.getCurrentInstance();
   final FacesMessage facesMessage = FacesMessageUtil.getMessage(context, messageCode, args);
   String message = facesMessage.getDetail();
   if (message == null) {
     message = facesMessage.getSummary();
   }
   this.messageCode = messageCode;
   this.args = args;
   this.message = message;
   this.facesMessage = facesMessage;
 }
  /**
   * Encode a single faces message.
   *
   * @param context The involved faces context.
   * @param component The messages component.
   * @param message The queued faces message.
   * @param table Whether to render the messages as a HTML table or a HTML list.
   * @param showSummary Whether to show summary.
   * @param showDetail Whether to show detail.
   * @param escape Whether to HTML-escape message.
   * @param tooltip Whether to show tooltip.
   * @throws IOException When an I/O error occurs.
   */
  protected void encodeMessage(
      FacesContext context,
      OmniMessages component,
      FacesMessage message,
      boolean table,
      boolean showSummary,
      boolean showDetail,
      boolean escape,
      boolean tooltip)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    writer.startElement(table ? "tr" : "li", component);
    String severityName = SEVERITY_NAMES.get(message.getSeverity());
    writeAttribute(writer, component, severityName + "Style", "style");
    writeAttribute(writer, component, severityName + "Class", "class", "styleClass");

    if (table) {
      writer.startElement("td", component);
    }

    String summary = coalesce(message.getSummary(), "");
    String detail = coalesce(message.getDetail(), summary);

    if (tooltip) {
      writeAttribute(writer, "title", detail);
    }

    if (showSummary) {
      writeText(writer, component, summary, escape);

      if (showDetail) {
        writer.write(" ");
      }
    }

    if (showDetail) {
      writeText(writer, component, detail, escape);
    }

    if (table) {
      writer.endElement("td");
    }

    writer.endElement(table ? "tr" : "li");
  }
 private static void replaceIdWithLabel(
     String clientId, FacesMessage message, FacesContext facesContext) {
   UIComponent label = findLabelFor(facesContext.getViewRoot(), clientId);
   if (label != null) {
     int idx = clientId.lastIndexOf(':');
     if (idx >= 0) {
       clientId = clientId.substring(idx + 1);
     }
     log.debug("Replacing ID with Label for: " + clientId);
     String text = (String) label.getAttributes().get("value");
     String detail = message.getDetail();
     String summary = message.getSummary();
     message.setSummary(summary.replaceAll(clientId, text));
     message.setDetail(detail.replaceAll(clientId, text));
   } else {
     log.debug("Unabled to find a label for ID: " + clientId);
   }
 }
 private static void appendMessagesForClientId(
     FacesContext facesContext, String clientId, StringBuffer jsTxt) {
   Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
   boolean replaceIds = isReplaceId(facesContext);
   while (messages.hasNext()) {
     FacesMessage message = messages.next();
     if (clientId == null) {
       jsTxt.append("\n{severity:'");
     } else {
       if (replaceIds) {
         replaceIdWithLabel(clientId, message, facesContext);
       }
       jsTxt.append("\n{clientId:'");
       jsTxt.append(clientId);
       jsTxt.append("', severity:'");
     }
     jsTxt.append(message.getSeverity());
     jsTxt.append("', summary:'");
     jsTxt.append(message.getSummary());
     jsTxt.append("', detail:'");
     jsTxt.append(message.getDetail());
     jsTxt.append("'},");
   }
 }
Beispiel #10
0
  public void execute(FacesContext facesContext) throws FacesException {

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Entering RenderResponsePhase");
    }
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("About to render view " + facesContext.getViewRoot().getViewId());
    }
    // For requests intended to produce a partial response, we need prohibit
    // writing any content outside of the view itself (f:view).
    if (facesContext.isAjaxRequest()) {
      facesContext.enableResponseWriting(false);
    }

    try {
      // Setup message display LOGGER.
      if (LOGGER.isLoggable(Level.INFO)) {
        Iterator<String> clientIdIter = facesContext.getClientIdsWithMessages();

        // If Messages are queued
        if (clientIdIter.hasNext()) {
          Set<String> clientIds = new HashSet<String>();

          // Copy client ids to set of clientIds pending display.
          while (clientIdIter.hasNext()) {
            clientIds.add(clientIdIter.next());
          }
          RequestStateManager.set(
              facesContext, RequestStateManager.CLIENT_ID_MESSAGES_NOT_DISPLAYED, clientIds);
        }
      }

      // render the view
      facesContext
          .getApplication()
          .getViewHandler()
          .renderView(facesContext, facesContext.getViewRoot());

      // display results of message display LOGGER
      if (LOGGER.isLoggable(Level.INFO)
          && RequestStateManager.containsKey(
              facesContext, RequestStateManager.CLIENT_ID_MESSAGES_NOT_DISPLAYED)) {

        // remove so Set does not get modified when displaying messages.
        Set<String> clientIds =
            TypedCollections.dynamicallyCastSet(
                (Set)
                    RequestStateManager.remove(
                        facesContext, RequestStateManager.CLIENT_ID_MESSAGES_NOT_DISPLAYED),
                String.class);
        if (!clientIds.isEmpty()) {

          // Display each message possibly not displayed.
          StringBuilder builder = new StringBuilder();
          for (String clientId : clientIds) {
            Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
            while (messages.hasNext()) {
              FacesMessage message = messages.next();
              builder.append("\n");
              builder.append("sourceId=").append(clientId);
              builder.append("[severity=(").append(message.getSeverity());
              builder.append("), summary=(").append(message.getSummary());
              builder.append("), detail=(").append(message.getDetail()).append(")]");
            }
          }
          LOGGER.log(Level.INFO, "jsf.non_displayed_message", builder.toString());
        }
      }
    } catch (IOException e) {
      throw new FacesException(e.getMessage(), e);
    }

    if (LOGGER.isLoggable(Level.FINEST)) {
      LOGGER.log(
          Level.FINEST,
          "+=+=+=+=+=+= View structure printout for " + facesContext.getViewRoot().getViewId());
      DebugUtil.printTree(facesContext.getViewRoot(), LOGGER, Level.FINEST);
    }

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Exiting RenderResponsePhase");
    }
  }
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) {
      return;
    }

    UIMessages messages = (UIMessages) component;
    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    // String clientId = ((UIMessages) component).getFor();
    String clientId = null; // PENDING - "for" is actually gone now
    // if no clientId was included
    if (clientId == null) {
      // and the author explicitly only wants global messages
      if (messages.isGlobalOnly()) {
        // make it so only global messages get displayed.
        clientId = "";
      }
    }

    // "for" attribute optional for Messages
    Iterator messageIter = getMessageIter(context, clientId, component);

    assert (messageIter != null);

    if (!messageIter.hasNext()) {
      return;
    }

    boolean showSummary = messages.isShowSummary();
    boolean showDetail = messages.isShowDetail();

    while (messageIter.hasNext()) {
      FacesMessage curMessage = (FacesMessage) messageIter.next();

      // make sure we have a non-null value for summary and
      // detail.
      String summary = (null != (summary = curMessage.getSummary())) ? summary : "";
      // Default to summary if we have no detail
      String detail = (null != (detail = curMessage.getDetail())) ? detail : summary;

      String severityStyleClass = null;
      String errorType = "default";
      long timeout = 5;
      if (curMessage.getSeverity() == FacesMessage.SEVERITY_INFO) {
        severityStyleClass = (String) component.getAttributes().get("infoClass");
        errorType = "info";
      } else if (curMessage.getSeverity() == FacesMessage.SEVERITY_WARN) {
        severityStyleClass = (String) component.getAttributes().get("warnClass");
        errorType = "warn";
      } else if (curMessage.getSeverity() == FacesMessage.SEVERITY_ERROR) {
        severityStyleClass = (String) component.getAttributes().get("errorClass");
        errorType = "error";
        timeout = 0;
      } else if (curMessage.getSeverity() == FacesMessage.SEVERITY_FATAL) {
        severityStyleClass = (String) component.getAttributes().get("fatalClass");
        errorType = "fatal";
        timeout = 0;
      }

      if (Framework.getProperty("org.nuxeo.ecm.tester.name") != null) {
        timeout = 0;
      }

      writer.startElement("script", messages);
      writer.writeAttribute("type", "text/javascript", null);

      String scriptContent =
          "jQuery(document).ready(function() {\n"
              + "  jQuery.ambiance({\n"
              + "    "
              + "message: \"%s\",\n"
              + "    title: \"%s\",\n"
              + "    type: \"%s\",\n"
              + "    className: \"%s\",\n"
              + "    timeout: \"%d\""
              + "  })\n"
              + "});\n";
      String formattedScriptContent;
      if (showDetail) {
        formattedScriptContent =
            String.format(scriptContent, detail, summary, errorType, severityStyleClass, timeout);
      } else {
        formattedScriptContent =
            String.format(scriptContent, "", summary, errorType, severityStyleClass, timeout);
      }
      writer.writeText(formattedScriptContent, null);
      writer.endElement("script");
    }
  }
Beispiel #12
0
 public Message(FacesMessage msg) {
   this.severity = msg.getSeverity().getOrdinal();
   this.summary = msg.getSummary();
   this.detail = msg.getDetail();
 }
  private void encodeSeverityMessages(
      FacesContext facesContext, Growl uiGrowl, String severity, List<FacesMessage> messages)
      throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();

    for (FacesMessage msg : messages) {
      String summary = msg.getSummary() != null ? msg.getSummary() : "";
      String detail = msg.getDetail() != null ? msg.getDetail() : summary;
      if (uiGrowl.isEscape()) {
        summary = BsfUtils.escapeHtml(summary);
        detail = BsfUtils.escapeHtml(detail);
      }
      summary = summary.replace("'", "\\\'");
      detail = detail.replace("'", "\\\'");
      // Decode messageType to map bootstrap alert styles
      String messageType = "success";
      if ("info".equals(severity)) {
        messageType = "info";
      } else if ("warn".equals(severity)) {
        messageType = "warning";
      } else if ("error".equals(severity)) {
        messageType = "danger";
      } else if ("fatal".equals(severity)) {
        messageType = "danger";
      }

      String icon =
          uiGrowl.getIcon() != null
              ? "glyphicon glyphicon-" + uiGrowl.getIcon()
              : "glyphicon glyphicon-warning-sign";

      String from = BsfUtils.StringOrDefault(uiGrowl.getPlacementFrom(), "top");
      String align = BsfUtils.StringOrDefault(uiGrowl.getPlacementAlign(), "right");

      writer.writeText(
          ""
              + " 	$.notify({"
              + " 		title: '"
              + (uiGrowl.isShowSummary() ? summary : "")
              + "', "
              + " 		message: '"
              + (uiGrowl.isShowDetail() ? detail : "")
              + "', "
              + " 		icon: '"
              + icon
              + "'"
              + " 	}, {"
              + " 		position: null, "
              + " 		type: '"
              + messageType
              + "', "
              + "		allow_dismiss: "
              + uiGrowl.isAllowDismiss()
              + ", "
              + "		newest_on_top: "
              + uiGrowl.isNewestOnTop()
              + ", "
              + "       delay: "
              + uiGrowl.getDelay()
              + ", "
              + "       timer: "
              + uiGrowl.getTimer()
              + ", "
              + " 		placement: { "
              + "			from: '"
              + from
              + "',"
              + "			align: '"
              + align
              + "'"
              + " 		}, "
              + "		animate: { "
              + "			enter: 'animated fadeInDown', "
              + "			exit: 'animated fadeOutUp' "
              + "		} "
              + "   }); "
              + "",
          null);
    }
  }
 public String getDetail() {
   return message.getDetail();
 }