Ejemplo n.º 1
0
  /** @see FacesContext#addMessage(String, javax.faces.application.FacesMessage) */
  public void addMessage(String clientId, FacesMessage message) {
    assertNotReleased();
    // Validate our preconditions
    Util.notNull("message", message);

    if (maxSeverity == null) {
      maxSeverity = message.getSeverity();
    } else {
      Severity sev = message.getSeverity();
      if (sev.getOrdinal() > maxSeverity.getOrdinal()) {
        maxSeverity = sev;
      }
    }

    if (componentMessageLists == null) {
      componentMessageLists = new LinkedHashMap<String, List<FacesMessage>>();
    }

    // Add this message to our internal queue
    List<FacesMessage> list = componentMessageLists.get(clientId);
    if (list == null) {
      list = new ArrayList<FacesMessage>();
      componentMessageLists.put(clientId, list);
    }
    list.add(message);
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine(
          "Adding Message[sourceId="
              + (clientId != null ? clientId : "<<NONE>>")
              + ",summary="
              + message.getSummary()
              + ")");
    }
  }
 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;
 }
  @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());
    }
  }
Ejemplo n.º 4
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());
      }
    }
  }
 private static boolean isInvalid(FacesContext facesContext, String clientId) {
   Iterator<FacesMessage> messages = facesContext.getMessages(clientId);
   while (messages.hasNext()) {
     FacesMessage message = messages.next();
     if (message.getSeverity().getOrdinal() > FacesMessage.SEVERITY_INFO.getOrdinal()) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 6
0
  /**
   * Verifica se existe alguma mensagem de erro no {@link FacesMessage}
   *
   * @return <code>true</code> caso exista, e <code>false</code> caso contrário.
   */
  public boolean possuiMensagemErro() {
    Iterator<FacesMessage> messages = facesContext.getMessages();
    while (messages.hasNext()) {
      FacesMessage msg = messages.next();

      if (msg.getSeverity().equals(FacesMessage.SEVERITY_ERROR)) {
        return true;
      }
    }
    return false;
  }
  public int handleNavigation(SelectLevelEvent event) {
    // if any error message is present, do not navigate
    boolean error = false;
    List<FacesMessage> messages = FacesContext.getCurrentInstance().getMessageList(null);
    for (FacesMessage msg : messages) {
      if (msg.getSeverity() == FacesMessage.SEVERITY_ERROR) {
        error = true;
        break;
      }
    }

    return error ? event.getCurrentLevel() : event.getNewLevel();
  }
  public static boolean hasErrors() {
    Iterator<FacesMessage> messages = FacesContext.getCurrentInstance().getMessages();

    for (; messages.hasNext(); ) {
      FacesMessage message = messages.next();

      if (message.getSeverity().compareTo(FacesMessage.SEVERITY_ERROR) == 0) {
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 9
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());
    }
  }
Ejemplo n.º 10
0
  /**
   * 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");
  }
Ejemplo n.º 11
0
  @Override
  public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
    if (!component.isRendered()) {
      return;
    }

    Growl uiGrowl = (Growl) component;
    ResponseWriter writer = facesContext.getResponseWriter();

    String clientId = uiGrowl.getClientId(facesContext);
    Iterator<FacesMessage> allMessages =
        uiGrowl.isGlobalOnly() ? facesContext.getMessages(null) : facesContext.getMessages();
    Map<String, List<FacesMessage>> messages = new HashMap<String, List<FacesMessage>>();
    messages.put("info", new ArrayList<FacesMessage>()); // Bootstrap info
    messages.put("warn", new ArrayList<FacesMessage>()); // Bootstrap warning
    messages.put("error", new ArrayList<FacesMessage>()); // Bootstrap Error
    messages.put("fatal", new ArrayList<FacesMessage>()); // Bootstrap Success

    while (allMessages.hasNext()) {

      FacesMessage message = allMessages.next();
      Severity severity = message.getSeverity();
      if (message.isRendered() && !uiGrowl.isRedisplay()) {
        continue;
      }

      if (severity.equals(FacesMessage.SEVERITY_INFO)) messages.get("info").add(message);
      else if (severity.equals(FacesMessage.SEVERITY_WARN)) messages.get("warn").add(message);
      else if (severity.equals(FacesMessage.SEVERITY_ERROR)) messages.get("error").add(message);
      else if (severity.equals(FacesMessage.SEVERITY_FATAL)) messages.get("fatal").add(message);
    }

    writer.startElement("script", uiGrowl);
    writer.writeAttribute("id", clientId, "id");
    writer.writeText("$(function() { ", null);
    for (String severity : messages.keySet()) {
      List<FacesMessage> severityMessages = messages.get(severity);
      if (severityMessages.size() > 0) {
        encodeSeverityMessages(facesContext, uiGrowl, severity, severityMessages);
      }
    }
    writer.writeText("});", null);

    writer.endElement("script");
  }
 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("'},");
   }
 }
Ejemplo n.º 13
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");
    }
  }
Ejemplo n.º 14
0
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) return;

    boolean mustRender = shouldWriteIdAttribute(component);

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

    String clientId = ((UIMessages) component).getFor();
    if (clientId == null) if (messages.isGlobalOnly()) clientId = "";

    Iterator messageIter = getMessageIter(context, clientId, component);

    assert (messageIter != null);
    if (!messageIter.hasNext()) {
      if (mustRender) {
        if ("javax_faces_developmentstage_messages".equals(component.getId())) {
          return;
        }
        writer.startElement("div", component);
        writeIdAttributeIfNecessary(context, writer, component);
        writer.endElement("div");
      }
      return;
    }

    writeIdAttributeIfNecessary(context, writer, component);

    // style is rendered as a passthru attribute
    RenderKitUtils.renderPassThruAttributes(context, writer, component, ATTRIBUTES);

    Map<Severity, List<FacesMessage>> msgs = new HashMap<Severity, List<FacesMessage>>();
    msgs.put(FacesMessage.SEVERITY_INFO, new ArrayList<FacesMessage>()); // Bootstrap info
    msgs.put(FacesMessage.SEVERITY_WARN, new ArrayList<FacesMessage>()); // Bootstrap warning
    msgs.put(FacesMessage.SEVERITY_ERROR, new ArrayList<FacesMessage>()); // Bootstrap error
    msgs.put(FacesMessage.SEVERITY_FATAL, new ArrayList<FacesMessage>()); // Bootstrap error

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

      if (curMessage.isRendered() && !messages.isRedisplay()) {
        continue;
      }
      msgs.get(curMessage.getSeverity()).add(curMessage);
    }

    List<FacesMessage> severityMessages = msgs.get(FacesMessage.SEVERITY_FATAL);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(
          context, component, messages, FacesMessage.SEVERITY_FATAL, severityMessages);
    }

    severityMessages = msgs.get(FacesMessage.SEVERITY_ERROR);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(
          context, component, messages, FacesMessage.SEVERITY_ERROR, severityMessages);
    }

    severityMessages = msgs.get(FacesMessage.SEVERITY_WARN);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(context, component, messages, FacesMessage.SEVERITY_WARN, severityMessages);
    }

    severityMessages = msgs.get(FacesMessage.SEVERITY_INFO);
    if (severityMessages.size() > 0) {
      encodeLoadingInfo(context, component, messages, FacesMessage.SEVERITY_INFO, severityMessages);
    }
  }
Ejemplo n.º 15
0
  @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");
    }
  }
Ejemplo n.º 16
0
 public Message(FacesMessage msg) {
   this.severity = msg.getSeverity().getOrdinal();
   this.summary = msg.getSummary();
   this.detail = msg.getDetail();
 }
Ejemplo n.º 17
0
 public Severity getSeverity() {
   return message.getSeverity();
 }