0

I'm having a bean class employee having attributes id,name along with public getters and setters.

I'm using following bean for db connection and getting values from database table.

TableBean.java:

  public class TableBean{
    public Connection getVConnection() throws Exception{
      String driver = "oracle.jdbc.driver.OracleDriver";
      String url = "jdbc:oracle:thin:@localhost:1521:globldb3";
      String username = "scott";
      String password = "tiger";
      Class.forName(driver);
      Connection conn = DriverManager.getConnection(url, username, password);
      return conn;
      }    
    public List<Employee> getPerInfoAll() {
    int i = 0;
    Connection conn = null;
    PreparedStatement pstmt = null;
    List<Employee> perInfoAll = new ArrayList(); 
     try {
        conn = getVConnection();
            String query = "select * from employee where e_id>5400";
            pstmt = conn.prepareStatement(query);
            rs = pstmt.executeQuery();
            while(rs.next()){
           System.out.println(rs.getString(1));
               perInfoAll.add(i,newEmployee(rs.getInt(1),rs.getString(2)));
               i++;
             }
             pstmt.close();
             rs.close();
             conn.close();    
      }catch (Exception e){
           e.printStackTrace();
      }
     return perInfoAll;
     }

Following is jsf page:

 <h:dataTable value="#{TableBean.perInfoAll}" var="e">
        <h:column>
            <f:facet name="header">Employee id</f:facet>
            <h:outputText value="#{e.id}">
        </h:column>

        <h:column>
            <f:facet name="header">Employee name</f:facet>
                     <h:outputText value="#{e.name}">
        </h:column>
    </h:dataTable>

Kindly reply. Thanks in advance.

1 Answer 1

2

I think it may be (again) a problem of getter/setter method naming. If your property is named

private List<Employee> perInfoAll

the getter method must be

public List<Employee> getPerInfoAll() { ... }

Notice the upper case "P" in the method name.

Furthermore, you don't need the semicolon after the el expression in your facelet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.