6 Replies Latest reply: Mar 23, 2012 2:20 PM by omar elassri RSS

    rich:dataTable  , richfaces 4.2.0

    omar elassri Newbie

      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