0 Replies Latest reply on Mar 17, 2008 4:51 PM by Sing Kit Chung

    Unable to refresh a datatable...

    Sing Kit Chung Newbie

      Hi Everybody,


      I am a Seam and JBDS newbie. In the simple Seam HelloWorld, my SayHello.xhtml displays an input text field to catch the name of a person, a SayHello button to submit the form, and a datatable that list all the names that have said hello.


      It persists the person's name ok but the table fails to refresh and display the name when the button is click the first time. The name shows up only when another name is
      entered and button is clicked again.


      Database table: Person in MySQL 5.0,
      3 Java classes : Person, PersonHome, PersonList,
      1 xhtml: SayHello.xhtml


      /**
       * Person.java generated by hbm2java
       */
      
      @Entity
      @Table(name = "person", catalog = "temp")
      public class Person implements java.io.Serializable {
           private Integer id;
           private String name;
           public Person() {
           }
           public Person(String name) {
                this.name = name;
           }
      
           @Id
           @GeneratedValue(strategy = IDENTITY)
           @Column(name = "id", unique = true, nullable = false)
           public Integer getId() {
                return this.id;
           }
           public void setId(Integer id) {
                this.id = id;
           }
      
           @Column(name = "name", nullable = false, length = 25)
           @NotNull
           @Length(max = 25)
           public String getName() {
                return this.name;
           }
           public void setName(String name) {
                this.name = name;
           }
      }
      
      /**
       * PersonHome.java generated by JBDS
       */
      @Name("personHome")
      public class PersonHome extends EntityHome<Person> {
      
           public void setPersonId(Integer id) {
                setId(id);
           }
           public Integer getPersonId() {
                return (Integer) getId();
           }
      
           @Override
           protected Person createInstance() {
                Person person = new Person();
                return person;
           }
           public void wire() {
           }
           public boolean isWired() {
                return true;
           }
           public Person getDefinedInstance() {
                return isIdDefined() ? getInstance() : null;
           }
      }
      
      /**
       * PersonList.java generated by JBDS
       */
      @Name("personList")
      public class PersonList extends EntityQuery {
      
           private static final String[] RESTRICTIONS = { "lower(person.name) like concat(lower(#{personList.person.name}),'%')", };
      
           private Person person = new Person();
      
           @Override
           public String getEjbql() {
                return "select person from Person person";
           }
      
           @Override
           public Integer getMaxResults() {
                return 25;
           }
      
           public Person getPerson() {
                return person;
           }
      
           @Override
           public List<String> getRestrictions() {
                return Arrays.asList(RESTRICTIONS);
           }
      
      }
      
      SayHello.xhtml:
      
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
           ............................
            template="layout/template.xhtml">
                             
      <ui:define name="body">
          <h:messages globalOnly="true" styleClass="message" 
              id="globalMessages"/>
          <h:form id="personSearch" styleClass="edit">
              <rich:simpleTogglePanel label="Person to say Hello"
               switchType="ajax">
               <s:decorate id="nameDecoration" template="layout/display.xhtml">
                    <ui:define name="label">name</ui:define>
                    <h:inputText id="name" required="true" value="#{personHome.instance.name}">
                              <s:validate />
                    </h:inputText>
                    <h:message for="name" styleClass="error" />
               </s:decorate>
              </rich:simpleTogglePanel>
              
             <div class="actionButtons">
                <h:commandButton id="search" value="Say Hello" 
                action="#{personHome.persist}"
                    rendered="#{true}">
                   </h:commandButton>
              </div>
          </h:form>
          
          <rich:panel>
            <f:facet name="header">The Following Persons Have Said Hello!</f:facet>
          <div class="results" id="personList" >
          <h:outputText value="No person exists" 
               rendered="#{empty personList.resultList}"/>
                     
          <rich:dataTable id="personList" 
                    var="person"
                    value="#{personList.resultList}" 
                 rendered="#{not empty personList.resultList}">
              <h:column>
               <f:facet name="header">
                <s:link styleClass="columnHeader"
                    value="id #{personList.order=='id asc' ? messages.down : ( personList.order=='id desc' ? messages.up : '' )}">
                    <f:param name="order" value="#{personList.order=='id asc' ? 'id desc' : 'id asc'}"/>
                 </s:link>
                </f:facet>
                  #{person.id}
              </h:column>
              <h:column>
               <f:facet name="header">
                  <s:link styleClass="columnHeader"
                     value="name #{personList.order=='name asc' ? messages.down : ( personList.order=='name desc' ? messages.up : '' )}">
                     <f:param name="order" value="#{personList.order=='name asc' ? 'name desc' : 'name asc'}"/>
                  </s:link>
                  </f:facet>
                  #{person.name}
              </h:column>
           
          </rich:dataTable>
          </div>
          </rich:panel>
      </ui:define>
      </ui:composition>
      



      Can somebody help to point out what tag I need to refresh the datatable so that it
      will update the data immediately after the button is clicked.


      Thanks in advance.


      Sing


      3-17-08