This discussion is archived
10 Replies Latest reply: Dec 12, 2008 1:18 PM by 843844 RSS

Property '' not readable on type java.lang.String

800663 Newbie
Currently Being Moderated
Im trying to get an array to show in JSF. using this code:

PersonBean.java
public class PersonBean {
   private static Name[] names = new Name[] {
       new Name("William", "Dupont"),
       new Name("Anna", "Keeney"),
       new Name("Mariko", "Randor"),
       new Name("John", "Wilson")
   };

   public PersonBean() {
       super();
   }

   public void setNames(Name[] nomre) { this.names = nomre;}
   public Name[] getNames() { return names;}

}
Test.java
class Name {
        private String first;
        private String last;

        public Name(String first, String last) {
           this.first = first;
           this.last = last;
        }

        public void setFirst(String newValue) { first = newValue; }
        public String getFirst() { return first; }

        public void setLast(String newValue) { last = newValue; }     
        public String getLast() { return last; }
}
faces-config.xml
     <managed-bean>
          <managed-bean-name>TestBean</managed-bean-name>
          <managed-bean-class>personclass.PersonBean</managed-bean-class>
          <managed-bean-scope>session</managed-bean-scope>
     </managed-bean>
datatable in jsf file:
<h:dataTable value="#{TestBean.names}" var="item">
                  <h:column>
                      <h:outputText value="#{item.last}"/>
                  </h:column>
         </h:dataTable>
What could be wrong? Thanks!
  • 1. Re: Property '' not readable on type java.lang.String
    843844 Newbie
    Currently Being Moderated
    You should be using a List or a DataModel in the datatable value.

    For more pointers and future hints, you may find this article useful: [http://balusc.blogspot.com/2006/06/using-datatables.html].
  • 2. Re: Property '' not readable on type java.lang.String
    800663 Newbie
    Currently Being Moderated
    Thank You for help, but i still have the same problem:

    My code at the moment:
    DataBase.java
    public class DataBase {
         //private String[] name = {"begin"};
        private List<Test> dataList;
          public List getData() {
    //           Test name = new Test();
                Session session = null;          
                try{
                    // This step will read hibernate.cfg.xml and prepare hibernate for use 
                    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
                    session = sessionFactory.openSession();               
                    //Create Select Clause HQL
                    //Test t = new Test();
                   String SQL_QUERY ="from Test test";
                    dataList = (List)session.createQuery(SQL_QUERY);
                    session.close();
                }catch(Exception e){
                     //e.getMessage();
                }finally{
                }
                return dataList;
         }
           
    }
    Test.java
    class Test {
         
           private long id;
           private String name;
           public long getId() {
             return id;
           }
           public String getName() {
                 return name;
             }
           public void setId(long Id) {
             this.id = Id;
           }
           public void setName(String strName) {
             this.name = strName;
           }
    
    }
    jsf:
    <h:dataTable value="#{DataBean.dataList}" var="item">
                      <h:column>
                          <h:outputText value="#{item.name}"/>
                      </h:column>
     </h:dataTable>
    Error:
    javax.servlet.ServletException: /pages/result.jsp(13,3) '#{DataBean.dataList}' Property 'dataList' not found on type personclass.DataBase
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
    I might have something wrong in DataBase.java as well, the way I add stuff to List. Im using Hibernate! It would be cool if someone helpmed me use a datamodel not a list here as well. Thanks!
  • 3. Re: Property '' not readable on type java.lang.String
    843844 Newbie
    Currently Being Moderated
    No, this is definitely not the same problem.
    javax.servlet.ServletException: /pages/result.jsp(13,3) '#{DataBean.dataList}' Property 'dataList' not found on type personclass.DataBase
    Read the exception message. The EL cannot find the property 'dataList' on type personclass.DataBase. With other words, the DataBase class is missing the getter method getDataList().
  • 4. Re: Property '' not readable on type java.lang.String
    800663 Newbie
    Currently Being Moderated
    Thank You, i got rid of the error, but i still don't get any results
    I know my code must be wrong near this: dataList = (List)session.createQuery(SQL_QUERY).list();
    What is the best way to do it or what am i getting wrong?
    public class DataBase {
         //private String[] name = {"begin"};
        private List<Test> dataList;
    
          public void getData() {
    //           Test name = new Test();
                Session session = null;          
                try{
                    // This step will read hibernate.cfg.xml and prepare hibernate for use 
                    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
                    session = sessionFactory.openSession();               
                    //Create Select Clause HQL
                    //Test t = new Test();
                   String SQL_QUERY ="from Test test";
                    dataList = (List)session.createQuery(SQL_QUERY).list();
                    session.close();
                }catch(Exception e){
                     //e.getMessage();
                }finally{
                }
                this.dataList = dataList;
         }
          public List getDataList(){
               return dataList;
          }
           
    }
  • 5. Re: Property '' not readable on type java.lang.String
    843844 Newbie
    Currently Being Moderated
    Either the getData() isn't been called to fill the list before getDataList() is invoked for the datatable, or there is an exception been thrown inside the try block of getData() while the catch block is ignoring it.
  • 6. Re: Property '' not readable on type java.lang.String
    800663 Newbie
    Currently Being Moderated
    Figured it out, and yet again, back in the beginning.
    javax.servlet.ServletException: /pages/result.jsp(15,22) '#{item.name}' Property 'name' not readable on type java.lang.String
    My database mapping:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="personclass.Test" table="test">
            <id name="Id" type="long" column="id" >
            <generator class="increment"/>
           </id>
           <property name="Name">
               <column name="name" />
           </property>
       </class>
    </hibernate-mapping>
    Test.java;
    class Test {
         
           private long id;
           private String name;
           public long getId() {
             return id;
           }
           public String getName() {
                 return name;
             }
           public void setId(long Id) {
             this.id = Id;
           }
           public void setName(String strName) {
             this.name = strName;
           }
    
    }
  • 7. Re: Property '' not readable on type java.lang.String
    843844 Newbie
    Currently Being Moderated
    You're passing a List of Strings to the datatable instead of a List of 'Test' DTO's.
  • 8. Re: Property '' not readable on type java.lang.String
    800663 Newbie
    Currently Being Moderated
    Thanks, i think i got it fixed. But now i have another problem, ofcourse my code ha changed alot, but what does this mean:
    javax.servlet.ServletException: /pages/dataTable.jsp(17,13) '#{item.name}' Error reading 'name' on type client.Client$$EnhancerByCGLIB$$70a4836d 
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
    The Client.java has the setter and getters for name,address...

    The name is a String.

    Thanks in advance.
  • 9. Re: Property '' not readable on type java.lang.String
    843844 Newbie
    Currently Being Moderated
    You're using Hibernate? The so-called CGLIB classes are proxy classes for lazy initialization. You need to initialize the classes using Hibernate#initialize(). For more details and help please consult documentation and forums at hibernate.org. This has nothing to do with JSF at all.
  • 10. Re: Property '' not readable on type java.lang.String
    843844 Newbie
    Currently Being Moderated
    hi,

    the problem is the declaration of your "Class Name" it must be declared as "public Class Name"

    with regards,

    ferudun