0 Replies Latest reply on Jan 19, 2009 2:06 PM by Suraj S

    Trouble populating Datatable

    Suraj S Newbie

      Hello!
      I've been trying to get a Datatable to display values from my table. I thought it was simple, but I'm certainly missing something here. All i see is a empty datatable.I'm able to see the contents of the ResultList obj, BTW here is my source code.


      DataTablebean.java - Backing Bean


      package com.org.MySeam;
      
      import java.util.List;
      import javax.persistence.EntityManager;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.datamodel.DataModel;
      
      @Name("dataforDistricts")
      public class DataTableBean {
           
      @In EntityManager entityManager;
      
      @DataModel
      private List<District> distlist=null;
      
          @Create
          public List<District> loadlist()
          {
           try{
                   
             distlist=(List<District>)entityManager.createQuery(" from District").getResultList();
              }
              catch(Exception e){
                   System.out.println("Exception..." + e);
                   e.printStackTrace();
              }
              return distlist;
          }
      
          public List<District> getDistlist() {
               return distlist;
          }
      
         public void setDistlist(List<District> distlist) {      
             this.distlist=distlist;
             
         }
      }
      



      District.java


      package com.org.MySeam;
      
      import static org.jboss.seam.ScopeType.SESSION;
      
      import java.io.Serializable;
      import java.util.List;
      import javax.persistence.Entity;
      ...........
      
      
      @Entity
      @Name("district")
      @Scope(SESSION)
      @Table(name="districts")
      
      public class District implements Serializable
      {
           @In EntityManager entityManager;
        
         private static final long serialVersionUID = 1L;
         private String distname;
         private String distname_mal;
         private String distcode;
        
         public District(String distname, String distcode, String distname_mal)
         { 
            this.distname = distname;
            this.distname_mal = distname_mal;
            this.distcode = distcode;
         }
         
        
        
         @NotNull
         public String getdistName()
         {
                 return distname;
         }
         
         @Id@NotNull @Length(min=3, max=3)
         public String getdistCode()
         {
            
            return distcode;
         }
         
         @NotNull
         public String getdistName_mal()
         {
            return distname_mal;
         }
         
         public void setdistName(String distname)
         {
              
            this.distname = distname;
         }
         
         public void setdistName_mal(String distname_mal)
         {
              
            this.distname_mal = distname_mal;
         }
         
         public void setdistCode(String distcode)
         {
            this.distcode = distcode;
         }
           
         @Override
         public String toString() 
         {
            return "District(" + distname + " "+distname_mal+" "+distcode+")";
         } 
       
      }
      
      


      addDistricts.xhtml


                 <rich:panel>
                        <f:facet name="header">
                            <h:outputText value="District Details"/>
                        </f:facet>                  
                 <rich:dataTable 
                 cellpadding="0" cellspacing="0" 
                 width="700" border="0" var="items" value="#{dataforDistricts.distlist}" style=" width : 1083px;" align="center">
                      
                          <f:facet name="header">
                              <rich:columnGroup>
       <rich:column colspan="3">
                                      <h:outputText value="DISTRICT INFORMATION" />
                                  </rich:column>
                                  
                                  <rich:column breakBefore="true">
                                 
                                      <h:outputText value="#{items.distCode}"></h:outputText>
                                  </rich:column>
                                  <rich:column>
                                
                                      <h:outputText value="#{items.distName}"></h:outputText>
                                  </rich:column>
                                  <rich:column>
                                 
                                    <h:outputText value="#{items.distName_mal}"></h:outputText>
                                  </rich:column>
                              </rich:columnGroup>
                          </f:facet>
                      </rich:dataTable>
                        </rich:panel>
      .....



      faces-config.xml


      <?xml version="1.0" encoding="UTF-8"?>
      <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xi="http://www.w3.org/2001/XInclude"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
       <managed-bean>
        <managed-bean-name>dataforDistricts</managed-bean-name>
        <managed-bean-class>com.org.MySeam.DataTableBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
       <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
        <locale-config>
         <default-locale>en</default-locale>
         <supported-locale>bg</supported-locale>
         <supported-locale>de</supported-locale>
         <supported-locale>en</supported-locale>
         <supported-locale>fr</supported-locale>
         <supported-locale>it</supported-locale>
         <supported-locale>tr</supported-locale>
        </locale-config>
       </application>
      </faces-config>