Package javax.faces.component

Examples of javax.faces.component.UIMessage


      UIComponent uiComponent) throws IOException {


    // FIXME: must be refactored! Bitte daran denken die msie version auch umzubauen!!!

    UIMessage component = (UIMessage) uiComponent;

    String clientId = ComponentUtil.findClientIdFor(component, facesContext);

    Iterator iterator = facesContext.getMessages(clientId);
View Full Code Here


      UIComponent uiComponent) throws IOException {


    // FIXME: must be refactored! Bitte daran denken die msie version auch umzubauen!!!

    UIMessage component = (UIMessage) uiComponent;

    String clientId = ComponentUtil.findClientIdFor(component, facesContext);

    Iterator iterator = facesContext.getMessages(clientId);
View Full Code Here

  public void encodeEndTobago(FacesContext facesContext,
      UIComponent uiComponent) throws IOException {


    UIMessage component = (UIMessage) uiComponent;

    String clientId = ComponentUtil.findClientIdFor(component, facesContext);

    Iterator iterator = facesContext.getMessages(clientId);
View Full Code Here

      UIComponent uiComponent) throws IOException {


    // FIXME: must be refactored! Bitte daran denken die msie version auch umzubauen!!!

    UIMessage component = (UIMessage) uiComponent;

    String clientId = ComponentUtil.findClientIdFor(component, facesContext);

    Iterator iterator = facesContext.getMessages(clientId);
View Full Code Here

    public void setUseDefaultClientValidationPresentationForApplication(boolean useDefaultClientValidationPresentationForApplication) {
        this.useDefaultClientValidationPresentationForApplication = useDefaultClientValidationPresentationForApplication;
    }

    public UIMessage getDefaultPresentationInstance(FacesContext context, ClientValidationSupport support) {
        UIMessage result;
        if (support == null) {
            result = getDefaultPresentationInstanceForApplication();
        } else {
            result = support.getDefaultPresentation();
            if (result == null) {
View Full Code Here

    }


    public void testMessageRenderer(UIComponent root) throws IOException {
        System.out.println("Testing MessageRenderer");
        UIMessage message = new UIMessage();
        message.setId("myMessage_0");
        message.setFor("myMessage_0");
        root.getChildren().add(message);

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

        MessageRenderer messageRenderer = new MessageRenderer();

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

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        String result = writer.toString();

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

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

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

        messageRenderer = new MessageRenderer();

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

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

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();
        //Span should have class attribute for styleClass
        //Summary and detail should be in body of span separated by space
        assertTrue(
            result.indexOf(
                "<span id=\"myMessage_1\" class=\"warnClass\">  global message summary_1 global message detail_1</span>") !=
            -1);

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

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

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

        messageRenderer = new MessageRenderer();

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

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

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();
        //Span should have style attribute
        //Summary and detail should be in body of span separated by space
        assertTrue(
            result.indexOf(
                "<span id=\"myMessage_2\" style=\"style\" class=\"errorClass\">  global message summary_2 global message detail_2</span>") !=
            -1);

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

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


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

        messageRenderer = new MessageRenderer();

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

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

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();

        //Span should have class attribute for styleClass and style attribute
        //Summary and detail should be in body of span separated by space
        assertTrue(
            result.indexOf(
                "<span id=\"myMessage_3\" style=\"style\" class=\"fatalClass\">  global message summary_3 global message detail_3</span>") !=
            -1);

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

        root.getChildren().remove(message);
        message = new UIMessage();
        message.setId("myMessage_4");
        message.setFor("myMessage_4");
        root.getChildren().add(message);

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

        messageRenderer = new MessageRenderer();

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

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

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

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();

        //Span should containt class for styleClass, style,
        //  and title for tooltip attributes
        //Summary should go in the title attribute and only the
        //  detail displayed in the body of the span
        assertTrue(
            result.indexOf(
                "<span id=\"myMessage_4\" style=\"style\" class=\"styleClass\" title=\"global message summary_4\">  global message detail_4</span>") !=
            -1);

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

        root.getChildren().remove(message);
        message = new UIMessage();
        message.setId("myMessage_5");
        message.setFor("myMessage_5");
        root.getChildren().add(message);

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

        messageRenderer = new MessageRenderer();

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

        //set tooltip criteria to true
        message.getAttributes().put("tooltip", new Boolean(true));
        message.setShowDetail(true);
        message.setShowSummary(true);
        message.getAttributes().put("warnClass", "warnClass");
        message.getAttributes().put("errorClass", "errorClass");
        message.getAttributes().put("infoClass", "infoClass");
        message.getAttributes().put("fatalClass", "fatalClass");

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

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();
        //Span should containt class for styleClass, style,
        //  and title for tooltip attributes
        //Summary should go in the title attribute and only the
        //  detail displayed in the body of the span
        //Should be wrapped in a table
        assertTrue(
            result.indexOf(
                "<span id=\"myMessage_5\" style=\"style\" class=\"fatalClass\" title=\"global message summary_5\">  global message detail_5</span>") !=
            -1);

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

        //
        // test showSummary(false) works
        //

        root.getChildren().remove(message);
        message = new UIMessage();
        message.setId("myMessage_6");
        message.setFor("myMessage_6");
        root.getChildren().add(message);

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

        messageRenderer = new MessageRenderer();

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

        // populate facescontext with some errors
        getFacesContext().addMessage(message.getFor(),
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_6",
                                         "global message detail_6"));

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();

        // should not contain summary.
        assertTrue(-1 != result.indexOf("global message detail_6"));
        assertEquals(-1, result.indexOf("global message summary_6"));

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

        //
        // test showDetail(false) works
        //

        root.getChildren().remove(message);
        message = new UIMessage();
        message.setId("myMessage_6");
        message.setFor("myMessage_6");
        root.getChildren().add(message);

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

        messageRenderer = new MessageRenderer();

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

        // populate facescontext with some errors
        getFacesContext().addMessage(message.getFor(),
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_6",
                                         "global message detail_6"));

        // test encode method

        messageRenderer.encodeBegin(getFacesContext(), message);
        messageRenderer.encodeEnd(getFacesContext(), message);

        result = writer.toString();

        // should not contain detail.
        assertEquals(-1, result.indexOf("global message detail_6"));
        assertTrue(-1 != result.indexOf("global message summary_6"));

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

        //
        // test showDetail(false), showSummary(false) works
        //

        root.getChildren().remove(message);
        message = new UIMessage();
        message.setId("myMessage_6");
        message.setFor("myMessage_6");
        root.getChildren().add(message);

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

        messageRenderer = new MessageRenderer();

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

        // populate facescontext with some errors
        getFacesContext().addMessage(message.getFor(),
                                     new FacesMessage(
                                         FacesMessage.SEVERITY_FATAL,
                                         "global message summary_6",
                                         "global message detail_6"));
View Full Code Here

        createPresentationComponent("dfm" + idx, component, clientValidationSupport, vp);
    }

    private static void createPresentationComponent(String id, UIComponent component, ClientValidationSupport support, ValidationProcessor vp) throws IOException {
        FacesContext context = FacesContext.getCurrentInstance();
        UIMessage defaultMessage = vp.getDefaultPresentationInstance(context, support);

        if (defaultMessage instanceof FloatingIconMessage) {
            createFloatingIconMessage(context, id, component, (FloatingIconMessage) defaultMessage);
        } else {
            throw new IllegalStateException("Illegal default presentation component type. Expected FloatingIconMessage, actual " + defaultMessage.getClass());
        }
    }
View Full Code Here


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

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

        if (_for != null) {
            // FIXME Should it be "for"?
            if (FacesUtils.isExpression(_for)) {
                message.setValueBinding("_for", createValueBinding(_for));
            } else {
                message.setFor(_for);
            }
        }

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

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

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


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

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

        if (_for != null) {
            // FIXME Should it be "for"?
            if (FacesUtils.isExpression(_for)) {
                message.setValueBinding("_for", createValueBinding(_for));
            } else {
                message.setFor(_for);
            }
        }

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

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

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

        boolean mustRender = shouldWriteIdAttribute(component);

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

        UIMessage message = (UIMessage) component;

        String clientId = message.getFor();
        //"for" attribute required for Message. Should be taken care of
        //by TLD in JSP case, but need to cover non-JSP case.
        if (clientId == null) {
            if (logger.isLoggable(Level.WARNING)) {
                logger.warning("'for' attribute cannot be null");
            }
            return;
        }

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


        assert(messageIter != null);
        if (!messageIter.hasNext()) {
            if (mustRender) {
                // no message to render, but must render anyway
                writer.startElement("span", component);
                writeIdAttributeIfNecessary(context, writer, component);
                writer.endElement("span");
            } // otherwise, return without rendering
            return;
        }
        FacesMessage curMessage = (FacesMessage) messageIter.next();
        if (curMessage.isRendered() && !message.isRedisplay()) {
            return;
        }
        curMessage.rendered();

        String severityStyle = null;
        String severityStyleClass = null;
        boolean showSummary = message.isShowSummary();
        boolean showDetail = message.isShowDetail();

        // make sure we have a non-null value for summary and
        // detail.
        String summary = (null != (summary = curMessage.getSummary())) ?
                  summary : "";
View Full Code Here

TOP

Related Classes of javax.faces.component.UIMessage

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.