1 Reply Latest reply on Aug 22, 2013 7:47 PM by Brian Leathem

    Global messages not displaying in jsf2.0

    Balaji S Newbie

      I am not able to dispaly custom error msgs from bean to user using  FacesMessage.

      I am adding msg to addMessage() when user enter mobile no less than 10.

      But on my console I getting msg like below

       

      INFO  [javax.enterprise.resource.webcontainer.jsf.renderkit] (http-localhost/127.0.0.1:8888-3) WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.

      sourceId=null[severity=(ERROR 2), summary=(mobile no should be greater than 10 degits), detail=()].

       

      I am using jsf 2.1 , richfaces 4.0 and ,jboss EAP 6.0 servers

       

      Thanks:)

       

      # my Xhtml file

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

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

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

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

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

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

          <ui:composition>

      <h:head/>

      <link href="../../css/styles.css" rel="stylesheet" type="text/css" />      

      <h:form id="personform12" >

      <h:panelGrid id="test2343" width="80%">

              <rich:messages id="messages" globalOnly="true" errorClass="globalError" showSummary="true" showDetail="false"></rich:messages>

       

      </h:panelGrid>

       

      <h:panelGrid border="0" columns="3" width="90%" cellpadding="0" cellspacing="1" >

      <h:panelGroup styleClass="alignmentRight">

       

      <h:outputText value="#{bundle['id']}" />

      </h:panelGroup>

      <h:inputText id="id" value="#{personBean.pdto.id}" required="true">

      </h:inputText>

      <rich:message styleClass="error" for="id" />

       

      <h:panelGroup>

          <h:outputText value="#{bundle['name']}" />

      </h:panelGroup>

      <h:inputText id="name" value="#{personBean.pdto.name}" required="true"/>

      <rich:message styleClass="error" for="name" />

       

      <h:panelGroup styleClass="alignmentRight">

          <h:outputText value="city" />

      </h:panelGroup>

      <h:inputText id="city" value="#{personBean.pdto.city}" required="true"/>

      <rich:message styleClass="error" for="city" />

       

      <h:panelGroup styleClass="alignmentRight">

          <h:outputText value="state" />

      </h:panelGroup>

      <h:inputText id="state" value="#{personBean.pdto.state}" required="true"/>

      <rich:message styleClass="error" for="state" />

       

      <h:panelGroup styleClass="alignmentRight">

          <h:outputText value="mobile" />

      </h:panelGroup>

      <h:inputText id="mobile" value="#{personBean.pdto.mobile}" required="true">

      </h:inputText>

      <rich:message styleClass="error" for="mobile" />

       

       

      <h:panelGroup styleClass="alignmentRight">

      <h:outputText value="DOB" />

      </h:panelGroup>

      <rich:calendar style="height:25px" inputStyle="width:203px" required="true"

                                          showWeeksBar="false"

                                           boundaryDatesMode="scroll"

                                          id="dob" value="#{personBean.pdto.dob}"

                                          datePattern="dd/MM/yyyy" cellWidth="24px" cellHeight="22px" />

      <rich:message styleClass="error" for="dob" />

       

      </h:panelGrid>

       

      <br/><br/>

      <h:commandButton id="commandSubmit" value="Submit" action="#{personBean.save}"></h:commandButton>

      </h:form>

      </ui:composition>

      </html>

       

      #my jsf bean

       

      public class PersonJSFBean {

       

          private static final Logger  log = Logger.getLogger(PersonJSFBean.class);

          private PersonDTO pdto;

          private PersonManager personManager;

          /**

           * @return the pdto

           */

          public PersonDTO getPdto() {

              return pdto;

          }

          /**

           * @return the personManager

           */

          public PersonManager getPersonManager() {

              return personManager;

          }

          public String save(){

              String str = null;

              try {

       

                  if(pdto.getMobile().length()<10) {

                      System.out.println("inside the mobile no>>>>>>>>>>>"+pdto.getMobile());

                      FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "mobile no should be greater than 10 degits ", null);

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

       

                  }

       

       

              } catch (Exception e) {

                  System.out.println("Error occured>>>>>>>>>>>");

                  e.printStackTrace();

       

              }

              return str;

       

          }

          /**

           * @param pdto the pdto to set

           */

          public void setPdto(PersonDTO pdto) {

              this.pdto = pdto;

          }

          /**

           * @param personManager the personManager to set

           */

          public void setPersonManager(PersonManager personManager) {

              this.personManager = personManager;

          }

      }