JSF-更新页面上的JSF DataTable



我在我的JSF页面上有一个数据表,该数据可以在页面加载上动态填充,这要归功于balusc和odelya。




但是现在,当我尝试刷新JSF页面以从数据库中检索更新的数据时,我没有在数据库中获取更新的数据。

我已经通过以下链接了,但无法理解细微差别。!

JSF DATATABLE刷新页面上的加载

是您的bean范围配置为会话吗?

您是否试图更改其要求?

填充结果集后不要忘记关闭连接,这必须是cachedrowset

这是Core Javaserver Faces Book的一个示例:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.enterprise.context.RequestScoped;
import javax.sql.DataSource;
import javax.sql.rowset.CachedRowSet;
@ManagedBean
@RequestScoped
public class CustomerBean {
    @Resource(name = "jdbc/mydb")
    private DataSource ds;
    public ResultSet getAll() throws SQLException {
        Connection conn = ds.getConnection();
        try {
            Statement stmt = conn.createStatement();
            ResultSet result = stmt.executeQuery("SELECT * FROM Customers");
            CachedRowSet crs = new com.sun.rowset.CachedRowSetImpl();
            crs.populate(result);
            return crs;
        } finally {
            conn.close();
        }
    }
}
'@RequestScoped' should be added to refresh your bean File to get the new data.

最新更新