1 Reply Latest reply on Mar 24, 2008 2:35 PM by jacob.orshalick

    faces messages in entity class causes validation failure???

    wiggy

      Okay spent some more time trying to figure what was wrong in my code and observed that putting a faces messages togteher in an entity object caused my code to fail validation on a facelets form.  Remove the faces message and it works fine


      not sure if this is a bug but it doesnt feel right.



      first off i have a form (its used as an embedded <a4j:include in a <rich:tapPanel in my home.xhtml.


      here is the ui element included within a form in the home page.  This is called as part of a wizard - i include a listing page which triggers this person.xhtml page on a new return from a button on the listing page


      note the <s:decorate tags.


      
      <!DOCTYPE composition 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:s="http://jboss.com/products/seam/taglib"
      
                      xmlns:ui="http://java.sun.com/jsf/facelets"
      
                      xmlns:f="http://java.sun.com/jsf/core"
      
                      xmlns:h="http://java.sun.com/jsf/html"
      
                      xmlns:rich="http://richfaces.org/rich"
      
                      xmlns:a4j="http://richfaces.org/a4j"
      
                      template="layout/template.xhtml">
      
                             
      
      <ui:define name="body">
      
          
      
          <a4j:outputPanel ajaxRendered="true">
      
          <h:messages globalOnly="true" styleClass="message"/>
      
            
      
            <rich:panel id="personDetail">
      
                  <f:facet name="header">person</f:facet>
      
          
      
                  <s:decorate id="firstNameDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">First Name</ui:define>
      
                      <h:inputText id="firstName" required="true"
      
                                   value="#{person.firstName}"/>
      
                  </s:decorate>
      
        
      
                  <s:decorate id="lastNameDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Last Name</ui:define>
      
                      <h:inputText id="lastName" required="true"
      
                                   value="#{person.lastName}"/>
      
                  </s:decorate>
      
       
      
                   <s:decorate id="middleNameDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Middle Name</ui:define>
      
                      <h:inputText id="middleName" 
      
                                   value="#{person.middleName}"/>
      
                  </s:decorate>
      
          
      
                   <s:decorate id="nicknameDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Nickname</ui:define>
      
                      <h:inputText id="nickname" 
      
                                   value="#{person.nickName}"/>
      
                  </s:decorate>
      
                  
      
                  <s:decorate id="sexDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Sex</ui:define>
      
                          <h:selectOneMenu value="#{person.sex}" id="personSex" >
      
                              <f:selectItem itemLabel="unspecified" itemValue="unspecified"/>
      
                              <f:selectItem itemLabel="female" itemValue="female"/>
      
                                <f:selectItem itemLabel="male" itemValue="male"/>
      
                              </h:selectOneMenu>     
      
                   </s:decorate>
      
                  
      
                  <s:decorate id="dateOfBirthDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Date Of Birth</ui:define>
      
                      <h:inputText id="dateOfBirth" 
      
                                   value="#{person.dateOfBirth}">
      
                              <s:convertDateTime  type="date" dateStyle="medium"  pattern="dd/mm/yyyy" />
      
                         </h:inputText>     
      
                  </s:decorate>            
      
       
      
                  <s:decorate id="dateOfMarriageDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Date Of Birth</ui:define>
      
                      <h:inputText id="dateOfMarriage" 
      
                                   value="#{person.dateOfMarriage }">
      
                           <s:convertDateTime type="date" dateStyle="medium" pattern="dd/mm/yyyy"/>
      
                      </h:inputText>     
      
                  </s:decorate>            
      
       
      
                  <s:decorate id="dateOfDeathDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Date Of Death</ui:define>
      
                      <h:inputText id="dateOfDeath" 
      
                                   value="#{person.dateOfDeath}">
      
                              <s:convertDateTime type="date" dateStyle="short" pattern="dd/mm/yyyy"/>
      
                      </h:inputText>     
      
                  </s:decorate>            
      
      
                  <s:decorate id="descriptionDecoration" template="layout/edit.xhtml">
      
                      <ui:define name="label">Description</ui:define>
      
                      <h:inputText id="description" 
      
                                value="#{person.description}">
      
                      </h:inputText>     
      
                  </s:decorate>            
      
                  
      
                  <div style="clear:both"/>
      
                  
      
              </rich:panel>
      
      
              <div class="actionButtons">
      
                  <a4j:commandButton id="save" 
      
                                  value="Save" 
      
                                 action="#{personHome.persist}"
      
                               rendered="#{!personHome.managed}">
      
                  </a4j:commandButton>               
      
                  <a4j:commandButton id="update" 
      
                                  value="Update" 
      
                                 action="#{personHome.update}"
      
                               rendered="#{personHome.managed}">  
      
                  </a4j:commandButton>               
      
                         
      
                  <a4j:commandButton id="delete" 
      
                                  value="Delete" 
      
                                 action="#{personHome.remove}"
      
                               rendered="#{personHome.managed}">
      
                  </a4j:commandButton>
      
                         <a4j:commandButton view="/personList.xhtml"
      
                             action="#{personHome.clear}"
      
                                 id="done"
      
                                  value="Done">
      
                    </a4j:commandButton>
      
               </div>
      
              
      
          </a4j:outputPanel>
      
         
      
      </ui:define>
      
      
      </ui:composition>
      
      
      



      lets take the first one  - if we look at the backing entity (i have an @Factory method on the EntityHome class that returns the entity bean)


      
      @Entity 
      
      ...
      
      
           @Transient
      
          @In FacesMessages facesMessages;
      
       
      
      
      ...
      
      
           public String getFirstName()
      
           {
      
                return (firstName == null) ? "<null>" : firstName;
      
           }
      
      
           public void setFirstName(String firstName)
      
           {
      
                //facesMessages.add("called person set first name #0", (firstName != null) ? firstName : "<null>");
      
                this.firstName = (firstName != null) ? firstName : "<null>";
      
                if (getName().contains("generic node:"))
      
                     setName (firstName);
      
                else if (!getName().contains (firstName))
      
                     setName (firstName + " " + getLastName());
      
           }
      
      
      
      



      if i remove the comments on the faces messages then the web UI just errors when i submit the .persist method on the EntityHome object.



      if i comment out the facesMessages as shown the code works fine.  Leave it in and it errors with a validation failure in the .xhtml form saying it cant call the person.firstName method


      can someone explain this??


      there is a note in the seam documentation that the logger reference must be static for an entity object.  is this true for facesMessages reference ??  If so why?