4 Replies Latest reply on Jan 22, 2011 4:39 PM by cmathrusse

    Error messages not being displayed

    cmathrusse

      I'm using RichFaces 4 M5 and seem to have no issues rendering error messages that are associated to components. (validation, etc...)

       

      The problem I run into is when I when I raise an error from my backing bean, the message simply disappears. I see the error generated in the log file but no warnings about it unable to be displayed.

       

      My backing bean is as follows:

       

                public String calculate() {

            String msg = MessageUtils.getString("error.invalidSelection");

            logger.severe(msg);

            FacesMessage message = new FacesMessage(msg, msg);

            message.setSeverity(FacesMessage.SEVERITY_ERROR);

            FacesContext.getCurrentInstance().addMessage(null, message);

            return "failure";

                          }

       

      I don't have any navigation-rule configured for the "failure" outcome so no redirect is occurring.

       

      My xhtml page has the following:

       

        <ui:define name="content">

        <h:form id="request-form"> 

       

        <h:panelGrid>

                      <iii:welcome-message/>

       

                      <h:messages style="color:red"/> 

       

      So why isn't the FacesMessage appearing after the method returns?

       

      Thanks for the help...

        • 1. Error messages not being displayed
          ilya40umov

          1) Try to wrap your h:messages into a4j:outputPanel. Because when you are using ajax re-rendering your h:messages may not be re-rendred with other elements.

          2) If your message should be displayed after the navigation or a4j:outputPanel does not work for you, post your code, please.

          • 2. Error messages not being displayed
            cmathrusse

            Thank you for you assistance Ilya. Unfortunately the a4j:outputPanel did not resolve the issue. So I tried a very simple page with nothing more that a button that calls a test backing bean and creates an Error message. But that too does not render. So I've attached my code in hopes that you can identify what it is that I am doing incorrectly.

             

            My page:

            <ui:composition template="/include/layout.xhtml"

                xmlns="http://www.w3.org/1999/xhtml"

                xmlns:iii="http://intraxinc.com/iii"

                xmlns:ui="http://java.sun.com/jsf/facelets"

                xmlns:h="http://java.sun.com/jsf/html"

                xmlns:f="http://java.sun.com/jsf/core"

                xmlns:a4j="http://richfaces.org/a4j"

                xmlns:rich="http://richfaces.org/rich"

                xmlns:components="http://java.sun.com/jsf/composite/components"

                xmlns:util="http://java.sun.com/jsf/composite/components/util">

             

                <ui:define name="content">

                    <h:form id="test-form">  

                           

                              <h:messages style="color:red" globalOnly="true"/>

             

                              <h:panelGrid columns="2" width="100%" style="text-align: right;">

                                  <div/>

                                  <a4j:commandButton id="get-estimate-submit" status="busy-status" value="Try it" action="#{messageTest.calculate('test-form')}"/>

                                  <a4j:status name="busy-status" onstart="#{rich:component('busyModal')}.show()" onstop="#{rich:component('busyModal')}.hide()" />

                              </h:panelGrid>

                    </h:form>

                </ui:define>

            </ui:composition>

             

            My layout template:

            <html xmlns="http://www.w3.org/1999/xhtml"

              xmlns:ui="http://java.sun.com/jsf/facelets"

              xmlns:h="http://java.sun.com/jsf/html"

              xmlns:fn="http://java.sun.com/jsp/jstl/functions"

              xmlns:a4j="http://richfaces.org/a4j"

              xmlns:rich="http://richfaces.org/rich"

              xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">

            <f:view>

              <h:head>

              <h:outputStylesheet library="css" name="style.css" target="head" />

              </h:head>

             

              <h:body> 

              <ui:insert name="metadata" />

              <div id="container">

                                  <ui:insert name="content" />

              </div>

              </h:body>

             

                <ui:insert name="busyModal">

                    <ui:include src="/include/busy-modal.xhtml"/>

                </ui:insert>

            </f:view>

            </html>

             

            My busy modal:

            <?xml version='1.0' encoding='UTF-8' ?>

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

                                  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

            <ui:composition xmlns="http://www.w3.org/1999/xhtml"

              xmlns:ui="http://java.sun.com/jsf/facelets"

              xmlns:h="http://java.sun.com/jsf/html"

              xmlns:f="http://java.sun.com/jsf/core"

              xmlns:a4j="http://richfaces.org/a4j"

              xmlns:rich="http://richfaces.org/rich">

              <rich:popupPanel id="busyModal" minHeight="100" minWidth="300" height="110" width="300" zindex="2000" resizeable="false">

                    <f:facet name="header">

                        <h:outputText value="#{msgs.busyHeader}"></h:outputText>

                    </f:facet>

                    <h:panelGrid columns="1" cellpadding="2" cellspacing="0" width="100%" style="text-align:center;">

                        <h:outputText value="#{msgs.busyBody}" style="vertical-align: middle; horizontal-align: middle;" />

                        <h:graphicImage library="images" name="busy.gif"/>

                    </h:panelGrid>

                </rich:popupPanel>

            </ui:composition> 

             

             

            My backing bean:

             

            @ManagedBean(name = "messageTest")

            @SessionScoped

            public class MessagesTest {

             

                      private Logger logger = Logger.getLogger(getClass());

             

                      public String calculate(String form) {

             

                                String msg = "Test Exception!!";

                                logger.severe(msg);

                                FacesMessage message = new FacesMessage(msg, msg);

                                message.setSeverity(FacesMessage.SEVERITY_ERROR);

                                FacesContext.getCurrentInstance().addMessage(null, message);

             

              return "failure";

                      }

            }

             

             

            And again, thank you for your assistance.

            • 3. Error messages not being displayed
              ilya40umov

              1) h:messages won't be re-rendered without a4j:outputPanel or without re-rendering a parent tag for h:messages.

              Like this:

              a4j:commandButton render="wrap"

              <h:panelGroup id="wrap">

                   h:messages

              </...>

              2) Only as a matter of interest try to assign a message to particular element on form by id. And see if won't work.

              • 4. Error messages not being displayed
                cmathrusse

                Adding the following:

                 

                              <h:panelGroup id="global-messages">

                                    <h:messages style="color:red" globalOnly="true"/>

                              </h:panelGroup>

                 

                <a4j:commandButton id="get-estimate-submit" render="global-messages"/>

                 

                Resolved the issue. I can now display the global messages. And pertaining to assigning a message to a particular element id, that seemed to work with my ajax calls when I would specify a validator. I guess that is because the validator is supplied the component and each of my components on the page has an <h:message> associated with it. Those messages always render next to the component that they are associated with. The only issue I seemed to have was with the global messages but I guess that was due to the fact that I am using an <a4j:commandButton> rather than an <h:commandButton>.

                 

                Thank you so much for resolving my issue!!