Package javax.faces.component

Examples of javax.faces.component.UIMessages


        if (isComponentMessage(component)) {
            UIMessage uiMessage = (UIMessage) component;
            showSummary = uiMessage.isShowSummary();
            showDetail = uiMessage.isShowDetail();
        } else if (isComponentMessages(component)) {
            UIMessages uiMessages = (UIMessages) component;
            showSummary = uiMessages.isShowSummary();
            showDetail = uiMessages.isShowDetail();
            isMessages = true;
        }
        boolean escape = true;
        if (isComponentRichMessage(component)) {
            AbstractMessage richMessage = (AbstractMessage) component;
View Full Code Here


    }


    public void testMessagesRenderer(UIComponent root) throws IOException {
        System.out.println("Testing MessagesRenderer");
        UIMessages messages = new UIMessages();
        messages.setId("myMessage_0");
        String myFor = "myMessage_0";
        // messages.setFor("myMessage_0");
        root.getChildren().add(messages);

        ResponseWriter originalWriter = getFacesContext().getResponseWriter();
        UIViewRoot originalRoot = getFacesContext().getViewRoot();

        getFacesContext().setViewRoot((UIViewRoot) root);

        // setup a new HtmlResponseWriter using a StringWriter.
        // This allows us to capture the output and check for
        // correctness without using a goldenfile.
        StringWriter writer = new StringWriter();
        HtmlResponseWriter htmlWriter = new HtmlResponseWriter(writer,
                                                               "text/html",
                                                               "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        MessagesRenderer messagesRenderer = new MessagesRenderer();

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_INFO,
                                         "global message summary_0.0",
                                         "global message detail_0.0"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_INFO,
                                         "global message summary_0.1",
                                         "global message detail_0.1"));

        // test encode method

        messagesRenderer.encodeBegin(getFacesContext(), messages);
        messagesRenderer.encodeEnd(getFacesContext(), messages);

        String result = writer.toString();

        //no span should be rendered since none of the criteria was met
        assertTrue(result.indexOf("span") == -1);
        try {
            writer.close();
        } catch (IOException ioe) {
            ; // ignore
        }

        root.getChildren().remove(messages);
        messages = new UIMessages();
        messages.setId("myMessage_1");
        myFor = "myMessage_1";
        // messages.setFor("myMessage_1");
        messages.setShowDetail(true);
        messages.setShowSummary(true);
        messages.getAttributes().put("warnClass", "warnClass");
        messages.getAttributes().put("errorClass", "errorClass");
        messages.getAttributes().put("infoClass", "infoClass");
        messages.getAttributes().put("fatalClass", "fatalClass");
        root.getChildren().add(messages);

        writer = new StringWriter();
        htmlWriter = new HtmlResponseWriter(writer, "text/html", "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        messagesRenderer = new MessagesRenderer();

        //add a styleClass so span is rendered
        messages.getAttributes().put("styleClass", "styleClass");

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_WARN,
                                         "global message summary_1.0",
                                         "global message detail_1.0"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_WARN,
                                         "global message summary_1.1",
                                         "global message detail_1.1"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_WARN,
                                         "global message summary_1.1",
                                         "global message detail_1.1"));

        // test encode method

        messagesRenderer.encodeBegin(getFacesContext(), messages);
        messagesRenderer.encodeEnd(getFacesContext(), messages);

        result = writer.toString();
        //Verify Html list (<ul> with id/class
        assertTrue(
            result.indexOf("<ul id=\"myMessage_1\" class=\"styleClass\">")
                != -1);
        //Verify Html list items
        assertTrue(
            result.indexOf("<li class=\"infoClass\">") != -1);
        assertTrue(
            result.indexOf("<li class=\"warnClass\">") != -1);
        assertTrue(
            result.indexOf("<li class=\"fatalClass\">") != -1);

        try {
            writer.close();
        } catch (IOException ioe) {
            ; // ignore
        }

        root.getChildren().remove(messages);
        messages = new UIMessages();
        messages.setId("myMessage_2");
        // messages.setFor("myMessage_2");
        myFor = "myMessage_2";
        messages.getAttributes().put("warnClass", "warnClass");
        messages.getAttributes().put("errorClass", "errorClass");
        messages.getAttributes().put("infoClass", "infoClass");
        messages.getAttributes().put("fatalClass", "fatalClass");
        messages.setShowDetail(true);
        messages.setShowSummary(true);
        root.getChildren().add(messages);

        writer = new StringWriter();
        htmlWriter = new HtmlResponseWriter(writer, "text/html", "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        messagesRenderer = new MessagesRenderer();

        //add a style
        messages.getAttributes().put("style", "style");

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_ERROR,
                                         "global message summary_2.0",
                                         "global message detail_2.0"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_ERROR,
                                         "global message summary_2.1",
                                         "global message detail_2.1"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_ERROR,
                                         "global message summary_2.2",
                                         "global message detail_2.2"));

        // test encode method

        messagesRenderer.encodeBegin(getFacesContext(), messages);
        messagesRenderer.encodeEnd(getFacesContext(), messages);

        result = writer.toString();

        //Verify Html list (<ul> with id/style)
        assertTrue(
            result.indexOf("<ul id=\"myMessage_2\" style=\"style\">") != -1);

        //Verify Html item (<li> with class)
        assertTrue(
            result.indexOf("<li class=\"errorClass\">") != -1);

        try {
            writer.close();
        } catch (IOException ioe) {
            ; // ignore
        }

        root.getChildren().remove(messages);
        messages = new UIMessages();
        messages.setId("myMessage_3");
        // messages.setFor("myMessage_3");
        myFor = "myMessage_3";
        messages.getAttributes().put("warnClass", "warnClass");
        messages.getAttributes().put("errorClass", "errorClass");
        messages.getAttributes().put("infoClass", "infoClass");
        messages.getAttributes().put("fatalClass", "fatalClass");
        messages.setShowDetail(true);
        messages.setShowSummary(true);
        root.getChildren().add(messages);


        writer = new StringWriter();
        htmlWriter = new HtmlResponseWriter(writer, "text/html", "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        messagesRenderer = new MessagesRenderer();

        //add a styleClass so span is rendered
        messages.getAttributes().put("styleClass", "styleClass");
        messages.getAttributes().put("style", "style");

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_3.0",
                                         "global message detail_3.0"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_3.1",
                                         "global message detail_3.1"));

        // test encode method

        messagesRenderer.encodeBegin(getFacesContext(), messages);
        messagesRenderer.encodeEnd(getFacesContext(), messages);

        result = writer.toString();

        //Verify Html list (<ul> with id/style/class)
        assertTrue(
            result.indexOf("<ul id=\"myMessage_3\" class=\"styleClass\" style=\"style\">") != -1);
        //Verify Html item (<li> with class)
        assertTrue(
            result.indexOf("<li class=\"fatalClass\">") != -1);
        try {
            writer.close();
        } catch (IOException ioe) {
            ; // ignore
        }

        root.getChildren().remove(messages);
        messages = new UIMessages();
        messages.setId("myMessage_4");
        // messages.setFor("myMessage_4");
        myFor = "myMessage_4";
        messages.getAttributes().put("warnClass", "warnClass");
        messages.getAttributes().put("errorClass", "errorClass");
        messages.getAttributes().put("infoClass", "infoClass");
        messages.getAttributes().put("fatalClass", "fatalClass");
        root.getChildren().add(messages);

        writer = new StringWriter();
        htmlWriter = new HtmlResponseWriter(writer, "text/html", "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        messagesRenderer = new MessagesRenderer();

        //add a styleClass so span is rendered
        messages.getAttributes().put("styleClass", "styleClass");
        messages.getAttributes().put("style", "style");

        //set tooltip criteria to true
        messages.getAttributes().put("tooltip", new Boolean(true));
        messages.setShowDetail(true);
        messages.setShowSummary(true);

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_4.0",
                                         "global message detail_4.0"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_4.1",
                                         "global message detail_4.1"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_4.2",
                                         "global message detail_4.2"));

        // test encode method

        messagesRenderer.encodeBegin(getFacesContext(), messages);
        messagesRenderer.encodeEnd(getFacesContext(), messages);

        result = writer.toString();

        //Verify <ul> with id/style/class
        //Verify <li> with class;span containing tool tip     
        assertTrue(
            result.indexOf("<ul id=\"myMessage_4\" class=\"styleClass\" style=\"style\"><li class=\"infoClass\"><span title=\"global message summary_0\">") != -1);
        try {
            writer.close();
        } catch (IOException ioe) {
            ; // ignore
        }

        root.getChildren().remove(messages);
        messages = new UIMessages();
        messages.setId("myMessage_5");
        // messages.setFor("myMessage_5");
        myFor = "myMessage_5";
        root.getChildren().add(messages);

        writer = new StringWriter();
        htmlWriter = new HtmlResponseWriter(writer, "text/html", "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        messagesRenderer = new MessagesRenderer();

        //add a styleClass
        messages.getAttributes().put("styleClass", "styleClass");
        messages.getAttributes().put("style", "style");

        //set tooltip criteria to true
        messages.getAttributes().put("tooltip", new Boolean(true));
        messages.setShowDetail(true);
        messages.setShowSummary(true);

        //Set layout to table
        messages.getAttributes().put("layout", "table");

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_5.0",
                                         "global message detail_5.0"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_5.1",
                                         "global message detail_5.1"));
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_5.2",
                                         "global message detail_5.2"));

        // test encode method

        messagesRenderer.encodeBegin(getFacesContext(), messages);
        messagesRenderer.encodeEnd(getFacesContext(), messages);

        result = writer.toString();

        //Verify wrapped in <table>
        assertTrue(
            result.indexOf("<table id=\"myMessage_5\" class=\"styleClass\" style=\"style\">") != -1);
        assertTrue(
            result.indexOf("<tr><td><span title=\"global message summary_5.0\">") != -1);

        try {
            writer.close();
        } catch (IOException ioe) {
            ; // ignore
        }

        root.getChildren().remove(messages);
        messages = new UIMessages();
        messages.setId("myMessage_6");
        // messages.setFor("myMessage_6");
        myFor = "myMessage_6";
        root.getChildren().add(messages);

        writer = new StringWriter();
        htmlWriter = new HtmlResponseWriter(writer, "text/html", "ISO-8859-1");
        getFacesContext().setResponseWriter(htmlWriter);

        messagesRenderer = new MessagesRenderer();

        //add a styleClass
        messages.getAttributes().put("styleClass", "styleClass");
        messages.getAttributes().put("style", "style");

        //set tooltip criteria to false
        messages.getAttributes().put("tooltip", new Boolean(false));
        messages.setShowDetail(false);
        messages.setShowSummary(true);

        //Set layout to table
        messages.getAttributes().put("layout", "table");

        // populate facescontext with some errors
        getFacesContext().addMessage(myFor,
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
View Full Code Here


    protected void setProperties(UIComponent component) {
        super.setProperties(component);

        UIMessages messages = null;
        try {
            messages = (UIMessages) component;
        } catch (ClassCastException cce) {
            throw new FacesException("Tag <" + getClass().getName() + "> expected UIMessages. " +
                                     "Got <" + component.getClass().getName() + ">");
        }

        if (globalOnly != null) {
            if (FacesUtils.isExpression(globalOnly)) {
                messages.setValueBinding("globalOnly", createValueBinding(globalOnly));
            } else {
                messages.setGlobalOnly(BooleanUtils.toBoolean(globalOnly));
            }
        }

        if (showDetail != null) {
            if (FacesUtils.isExpression(showDetail)) {
                messages.setValueBinding("showDetail", createValueBinding(showDetail));
            } else {
                messages.setShowDetail(BooleanUtils.toBoolean(showDetail));
            }
        }

        if (showSummary != null) {
            if (FacesUtils.isExpression(showSummary)) {
                messages.setValueBinding("showSummary", createValueBinding(showSummary));
            } else {
                messages.setShowSummary(BooleanUtils.toBoolean(showSummary));
            }
        }

        setProperty(component, "errorClass", errorClass);
        setProperty(component, "errorStyle", errorStyle);
View Full Code Here


    protected void setProperties(UIComponent component) {
        super.setProperties(component);

        UIMessages messages = null;
        try {
            messages = (UIMessages) component;
        } catch (ClassCastException cce) {
            throw new FacesException("Tag <" + getClass().getName() + "> expected UIMessages. " +
                                     "Got <" + component.getClass().getName() + ">");
        }

        if (globalOnly != null) {
            if (FacesUtils.isExpression(globalOnly)) {
                messages.setValueBinding("globalOnly", createValueBinding(globalOnly));
            } else {
                messages.setGlobalOnly(BooleanUtils.toBoolean(globalOnly));
            }
        }

        if (showDetail != null) {
            if (FacesUtils.isExpression(showDetail)) {
                messages.setValueBinding("showDetail", createValueBinding(showDetail));
            } else {
                messages.setShowDetail(BooleanUtils.toBoolean(showDetail));
            }
        }

        if (showSummary != null) {
            if (FacesUtils.isExpression(showSummary)) {
                messages.setValueBinding("showSummary", createValueBinding(showSummary));
            } else {
                messages.setShowSummary(BooleanUtils.toBoolean(showSummary));
            }
        }

        setProperty(component, "errorClass", errorClass);
        setProperty(component, "errorStyle", errorStyle);
View Full Code Here

        }

        //  If id is user specified, we must render
        boolean mustRender = shouldWriteIdAttribute(component);

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

        String clientId = ((UIMessages) component).getFor();
        // 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()) {
            if (mustRender) {
                // no message to render, but must render anyway
                // but if we're writing the dev stage messages,
                // only write it if messages exist
                if ("javax_faces_developmentstage_messages".equals(component.getId())) {
                    return;
                }
                writer.startElement("div", component);
                writeIdAttributeIfNecessary(context, writer, component);
                writer.endElement("div");
            } // otherwise, return without rendering
            return;
        }

        String layout = (String) component.getAttributes().get("layout");
        boolean showSummary = messages.isShowSummary();
        boolean showDetail = messages.isShowDetail();
        String styleClass = (String) component.getAttributes().get(
              "styleClass");

        boolean wroteTable = false;

        //For layout attribute of "table" render as HTML table.
        //If layout attribute is not present, or layout attribute
        //is "list", render as HTML list.
        if ((layout != null) && (layout.equals("table"))) {
            writer.startElement("table", component);
            wroteTable = true;
        } else {
            writer.startElement("ul", component);
        }

        //Render "table" or "ul" level attributes.
        writeIdAttributeIfNecessary(context, writer, component);
        if (null != styleClass) {
            writer.writeAttribute("class", styleClass, "styleClass");
        }
        // style is rendered as a passthru attribute
        RenderKitUtils.renderPassThruAttributes(context,
                                                writer,
                                                component,
                                                ATTRIBUTES);

        while (messageIter.hasNext()) {
            FacesMessage curMessage = (FacesMessage) messageIter.next();
            if (curMessage.isRendered() && !messages.isRedisplay()) {
                continue;
            }
            curMessage.rendered();

            String severityStyle = null;
View Full Code Here

        }

        //  If id is user specified, we must render
        boolean mustRender = shouldWriteIdAttribute(component);

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

        String clientId = ((UIMessages) component).getFor();
        // 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()) {
            if (mustRender) {
                // no message to render, but must render anyway
                // but if we're writing the dev stage messages,
                // only write it if messages exist
                if ("javax_faces_developmentstage_messages".equals(component.getId())) {
                    return;
                }
                writer.startElement("div", component);
                writeIdAttributeIfNecessary(context, writer, component);
                writer.endElement("div");
            } // otherwise, return without rendering
            return;
        }

        String layout = (String) component.getAttributes().get("layout");
        boolean showSummary = messages.isShowSummary();
        boolean showDetail = messages.isShowDetail();
        String styleClass = (String) component.getAttributes().get(
              "styleClass");

        boolean wroteTable = false;

        //For layout attribute of "table" render as HTML table.
        //If layout attribute is not present, or layout attribute
        //is "list", render as HTML list.
        if ((layout != null) && (layout.equals("table"))) {
            writer.startElement("table", component);
            wroteTable = true;
        } else {
            writer.startElement("ul", component);
        }

        //Render "table" or "ul" level attributes.
        writeIdAttributeIfNecessary(context, writer, component);
        if (null != styleClass) {
            writer.writeAttribute("class", styleClass, "styleClass");
        }
        // style is rendered as a passthru attribute
        RenderKitUtils.renderPassThruAttributes(context,
                                                writer,
                                                component,
                                                ATTRIBUTES);

        while (messageIter.hasNext()) {
            FacesMessage curMessage = (FacesMessage) messageIter.next();
            if (curMessage.isRendered() && !messages.isRedisplay()) {
                continue;
            }
            curMessage.rendered();

            String severityStyle = null;
View Full Code Here

        return component instanceof AbstractMessages;
    }

    private String getFor(UIComponent component) {
        if (isComponentMessages(component)) {
            UIMessages messages = (UIMessages) component;
            if (messages.isGlobalOnly()) {
                return "";
            } else {
                return messages.getFor();
            }
        } else if (isComponentMessage(component)) {
            UIMessage message = (UIMessage) component;
            return message.getFor();
        } else {
View Full Code Here

        if (isComponentMessage(component)) {
            UIMessage uiMessage = (UIMessage) component;
            showSummary = uiMessage.isShowSummary();
            showDetail = uiMessage.isShowDetail();
        } else if (isComponentMessages(component)) {
            UIMessages uiMessages = (UIMessages) component;
            showSummary = uiMessages.isShowSummary();
            showDetail = uiMessages.isShowDetail();
            isMessages = true;
        }
        boolean escape = true;
        if (isComponentRichMessage(component)) {
            AbstractMessage richMessage = (AbstractMessage) component;
View Full Code Here

        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;
        }

        String layout = (String) component.getAttributes().get("layout");
        boolean showSummary = messages.isShowSummary();
        boolean showDetail = messages.isShowDetail();
        String styleClass = (String) component.getAttributes().get(
              "styleClass");

        boolean wroteTable = false;
View Full Code Here

        }

        //  If id is user specified, we must render
        boolean mustRender = shouldWriteIdAttribute(component);

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

        String clientId = ((UIMessages) component).getFor();
        // 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()) {
            if (mustRender) {
                // no message to render, but must render anyway
                // but if we're writing the dev stage messages,
                // only write it if messages exist
                if ("javax_faces_developmentstage_messages".equals(component.getId())) {
                    return;
                }
                writer.startElement("div", component);
                writeIdAttributeIfNecessary(context, writer, component);
                writer.endElement("div");
            } // otherwise, return without rendering
            return;
        }

        String layout = (String) component.getAttributes().get("layout");
        boolean showSummary = messages.isShowSummary();
        boolean showDetail = messages.isShowDetail();
        String styleClass = (String) component.getAttributes().get(
              "styleClass");

        boolean wroteTable = false;

        //For layout attribute of "table" render as HTML table.
        //If layout attribute is not present, or layout attribute
        //is "list", render as HTML list.
        if ((layout != null) && (layout.equals("table"))) {
            writer.startElement("table", component);
            wroteTable = true;
        } else {
            writer.startElement("ul", component);
        }

        //Render "table" or "ul" level attributes.
        writeIdAttributeIfNecessary(context, writer, component);
        if (null != styleClass) {
            writer.writeAttribute("class", styleClass, "styleClass");
        }
        // style is rendered as a passthru attribute
        RenderKitUtils.renderPassThruAttributes(context,
                                                writer,
                                                component,
                                                ATTRIBUTES);

        while (messageIter.hasNext()) {
            FacesMessage curMessage = (FacesMessage) messageIter.next();
            if (curMessage.isRendered() && !messages.isRedisplay()) {
                continue;
            }
            curMessage.rendered();

            String severityStyle = null;
View Full Code Here

TOP

Related Classes of javax.faces.component.UIMessages

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.