一个JSF页面多个bean的使用

时间:2014-12-12 22:22:57

标签: jsf

enter image description here

import java.sql.*;
import java.util.*;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "tableBeanb")
@SessionScoped
public class TableBeanb {

    Connection con;
    Statement ps;
    ResultSet rs;
    private List<perInfo> perInfoAll = new ArrayList<perInfo>();

    public List<perInfo> getperInfoAll() {

        try {

            Class.forName("org.postgresql.Driver");
            con = DriverManager.getConnection(
                    "jdbc:postgresql://127.0.0.1:5432/smart", "postgres",
                    "root");
            ps = con.createStatement();
            rs = ps.executeQuery("select count(eid) from \"Etkinlik\"");

            while (rs.next()) {
                System.out.println(rs.getString(1));
                perInfoAll.add(new perInfo(rs.getString(1)));

            }

            con.close();
            rs.close();
            ps.close();

        } catch (Exception e) {
            System.out.println("Error Data : " + e.getMessage());
        }
        return perInfoAll;
    }

    public class perInfo {

        String eid;

        public perInfo(String yname) {
            this.eid = yname;
        }

        public String getMid() {
            return eid;
        }
    }
}

这里的错误在哪里?

1 个答案:

答案 0 :(得分:0)

您在xhtml文件中使用了表达式#{item.eid}。 JSF使用Java bean convention来访问属性,而不是直接访问字段。这意味着JSF期望String getEid()类中的方法perInfo

因此,要么将getMid方法重命名为getEid,要么将#{item.eid}更改为#{item.mid}