/**
   * 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 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;
 }
Ejemplo n.º 3
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");
  }
  /**
   * 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");
  }
Ejemplo n.º 5
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);
    }
  }