简体   繁体   English

JSF-在页面刷新时更新JSF数据表

[英]JSF - Updating a JSF datatable on page refresh

I have a datatable on my JSF page, which gets filled dynamically on page load thanks to BalusC and Odelya. 我的JSF页面上有一个数据表,由于BalusC和Odelya,它在页面加载时会动态填充。

But now when I try to refresh the JSF page to retrieve the updated data from database, I don't get the updated data in the Datatable. 但是现在,当我尝试刷新JSF页面以从数据库检索更新的数据时,我没有在Datatable中获取更新的数据。

I have already gone through the following link but couldn't understand the nuances..! 我已经浏览了以下链接,但看不清细微差别..!

JSF datatable refresh on page load 页面加载时刷新JSF数据表

Is your bean scope configured as a Session? 您的bean作用域是否配置为会话?

Have you tried to change its scope to Request? 您是否尝试将其范围更改为“请求”?

Don't forget to close your connection after filling your resultset, which has to be a CachedRowSet 填写结果集后,不要忘记关闭连接,该结果集必须是CachedRowSet

Here is an example from Core JavaServer Faces book: 这是Core JavaServer Faces书中的一个示例:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM