【问题标题】:A JSF Page multiple bean use of一个 JSF Page 多个 bean 的使用
【发布时间】:2015-02-11 17:15:12
【问题描述】:

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;
        }
    }
}

这里的错误在哪里?

【问题讨论】:

    标签: jsf


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-04-11
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 2012-05-27
      • 2011-08-16
      • 1970-01-01
      • 2016-01-31
      • 2014-12-28
      相关资源
      最近更新 更多