6 Replies Latest reply on Mar 23, 2012 2:20 PM by ensemien

    rich:dataTable  , richfaces 4.2.0

    ensemien

      Hello everyone

       

      i am trying to display data from MySQL table (using : richfaces 4.2.0,spring ,hibernate) but i have one error

      below my sources code : ( Teacher.java ,TeacherService.java,TeacherServiceImpl.java, TeacherBean.java ,  testRich.xhtml )

       

      *Teacher.java

       

      package fr.sewatech.university.model; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; /** * Teacher generated by hbm2java */ @Entity @Table(name = "teacher", catalog = "university") public class Teacher implements java.io.Serializable {     private Integer id;     private String name;     private String forname;     private Integer age; // getters and setters }

       

      *TeacherBean.java

       

      package fr.sewatech.university.web;
      
      import java.io.Serializable;
      import java.util.List;
      
      import javax.annotation.PostConstruct;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.RequestScoped;
      import javax.faces.component.html.HtmlDataTable;
      
      import org.springframework.beans.factory.annotation.Autowired;
      import fr.sewatech.university.model.Teacher;
      import fr.sewatech.university.service.TeacherService;
      
      
      @ManagedBean
      @RequestScoped
      public class TeacherBean implements Serializable {
          
          @Autowired
          private transient TeacherService teacherService;
          private transient HtmlDataTable teacherTable;
          
          
          private List<Teacher> teacherList;
              
              
              @PostConstruct
              public void init() {
                  teacherList = teacherService.findAll();  // teacherList <-> items
               }
      
              public List<Teacher> getTeacherList() {
                  return teacherList;
              }
      
              public HtmlDataTable getTeacherTable() {
                  return teacherTable;
              }
      
      
              public void setTeacherTable(HtmlDataTable teacherTable) {
                  this.teacherTable = teacherTable;
              }
      
              public void setTeacherList(List<Teacher> teacherList) {
                  this.teacherList = teacherList;
              }
      
      }
      

      *testRich.xhtml

       

      and this is the error :

       

      Etat HTTP 500 [...] javax.servlet.ServletException: /testRich.xhtml @17,47 binding="#{teacherBean.teacherTable}": Cannot convert org.richfaces.component.UIDataTable@1f3104d0 of type class org.richfaces.component.UIDataTable to class javax.faces.component.html.HtmlDataTable javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) cause mère javax.el.ELException: /testRich.xhtml @17,47 binding="#{teacherBean.teacherTable}": Cannot convert org.richfaces.component.UIDataTable@1f3104d0 of type class org.richfaces.component.UIDataTable to class javax.faces.component.html.HtmlDataTable com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:139) com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1920) com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1132)  [.....]

      *TeachereService.java

       

      package fr.sewatech.university.service;
      import java.util.List;
      import fr.sewatech.university.model.Teacher;
      
      public interface TeacherService {
          List<Teacher> findAll();
       }
      

      *TeacherServiceImpl.java

       

      package fr.sewatech.university.service;
      
      import java.util.List;
      import org.hibernate.SessionFactory;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Service;
      import org.springframework.transaction.annotation.Transactional;
      import fr.sewatech.university.model.Teacher;
      
      
      @Service("teacherService")
      @Transactional
      public class TeacherServiceImpl implements TeacherService {
      
          @Autowired
          private SessionFactory sessionFactory;
           
          @SuppressWarnings("unchecked")
          @Override
          public List<Teacher> findAll() {
              // TODO Auto-generated method stub
              return sessionFactory.getCurrentSession().createQuery("From Teacher").list();
          }
      
      }
      

       

       

       

      i did the same example with richefaces 3.1.4 , <rich:scrollableDataTable> and it worked fine ,but frankly i am seduced by richefaces 4 and i want to make 

      my graduation project with it.  please, please  i need your help 

        • 1. Re: rich:dataTable  , richfaces 4.2.0
          sunkaram

          richfaces 4.2 doesn't have javax.faces.component.html.HtmlDataTable; class

           

          check if you are using correct jars or not..and change the code accordingly..

          • 2. Re: rich:dataTable  , richfaces 4.2.0
            ensemien

            this is my lib folder :

            Sans titre.png

            i am reading attentively the Ebook   practical richfaces second edition,but there is no how to get data from data base with rich:dataTable 

            • 3. Re: rich:dataTable  , richfaces 4.2.0
              ilya_shaikovsky

              i am reading attentively the Ebook   practical richfaces second edition,but there is no how to get data from data base with rich:dataTable 

               

              I will review the question in more details now but before could just say that actually the book has that in data iteratiopn chapter

              • 4. Re: rich:dataTable  , richfaces 4.2.0
                ensemien

                Hello , actually i haven't finished yet reading all the chapters, now i read  (Using Partial Table Updates)p205  ,frankly i am happy,because it 's  an interesting Ebook and i read it  slowly

                and attentively,and all the examples i  have coded works without any error.

                i will review the data iteration chapter meticulously .

                • 5. Re: rich:dataTable  , richfaces 4.2.0
                  sunkaram

                  Not sure why it is getting compiled..

                   

                  anyway try changing

                   

                  javax.faces.component.html.HtmlDataTable;

                  to

                  org.richfaces.component.UIDataTable

                  • 6. Re: rich:dataTable  , richfaces 4.2.0
                    ensemien

                    Hello , you are right  Sunkura , i  made  the change that you mentionned and it works fine now, thank you so much .

                     

                    for the other persons who have the same problem :

                    thread ricapitulatory :

                    problem: i am using richefaces 4.0.2 ,hibernate ,spring, i used <rich:dataTable> and  i hade the problem with loading data from mysql table (see above for more details about the error)

                    solution :  i change    private transient HtmlDataTable teacherTable; to:  private transient  org.richfaces.component.UIDataTable teacherTable;

                     

                    Thanks again