简体   繁体   English

请求作用域bean JSF

[英]request scoped bean JSF

I have a page tables.jspx that shows a dataTable of all tables and has a link to createTable.jspx; 我有一个表格tables.jspx,它显示所有表格的dataTable,并具有createTable.jspx的链接; when I create a new table it returns to tables.jspx but it doesn't show the list with the new table. 当我创建一个新表时,它将返回tables.jspx,但不会显示带有新表的列表。 (tablesBean and createTableBean are request scope). (tablesBean和createTableBean是请求范围)。 I follow the BalusC tutorial http://balusc.blogspot.com/2006/06/using-datatables.html initializing the list of tables in the getter lazily. 我遵循BalusC教程http://balusc.blogspot.com/2006/06/using-datatables.html懒惰地初始化getter中的表列表。 As far as I now if my bean is request scoped shouldn't be destroyed after the request is finished?. 就我现在而言,如果我的bean是请求范围的对象,在请求完成之后是否应该销毁它? The navigation is from tables.jspx -->createTable.jspx --> tables.jspx. 导航来自tables.jspx-> createTable.jspx-> tables.jspx。 I want that after I create the new table returns to the list of tables showing the fresh list with the new table. 我希望在创建新表后返回表列表,以显示带有新表的新列表。 Please help me to understand what I'm doing wrong. 请帮助我了解我在做什么错。

Here is my code that returns my list of tables in the getter (simplified): 这是我的代码,返回我在getter中的表列表(简化):

  public List getTables(){
    if(tables==null){ //lazy initialization for a request bean as recommended by BalusC
     //Return list of tables
    }

but if I change this line if(tables==null) for if(tables==null ||FacesContext.getCurrentInstance().getRenderResponse()) 但如果我改变这一行if(tables==null)if(tables==null ||FacesContext.getCurrentInstance().getRenderResponse())

my list is actualized when I return from createTable.jspx, that change is recommended when the bean is in session scope, but that brings me a problem with my dataPaginator and my sortColumn functions (as it returns the fresh data from DB when I sort the list by a column it returns the wrong row for edit because I have a link in each row for edit and delete) 我的列表是在我从createTable.jspx返回时实现的,建议在Bean处于会话范围内时进行此更改,但这给我的dataPaginator和sortColumn函数带来了问题(因为当我对按列列出它会返回错误的编辑行,因为我在每一行中都有一个用于编辑和删除的链接)

Because you didn't post code, I will use the tutorial you linked above to explain what might be happening... 因为您没有发布代码,所以我将使用上面链接的教程来解释可能发生的情况...

private void loadDataList() {

        // Do your "SELECT * FROM mydata" thing.
        try {
            dataList = dataDAO.list();
        } catch (DAOException e) {
            setErrorMessage(e.getMessage() + " Cause: " + e.getCause());
            e.printStackTrace();
        }
    }

You are correct that the request scoped bean tables will be created and destroyed TWICE here, but at each time it is constructed it is calling the method listed above. 您正确的说,将在这里创建并销毁请求范围的Bean tables ,但是每次构造它时,它都在调用上面列出的方法。 This will reinitialize the table based on the current data in the database. 这将基于数据库中的当前数据重新初始化表。

If createTable.jspx is supposed to modify the data in the database then perhaps those updates aren't occurring or that new data is being filtered out by your request bean. 如果应该使用createTable.jspx来修改数据库中的数据,则可能是未发生这些更新,或者请求bean正在过滤掉新数据。

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

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