请求作用域 bean JSF
我有一个页面tables.jspx,它显示所有表的dataTable,并有一个指向createTable.jspx的链接;当我创建新表时,它返回到tables.jspx,但不显示新表的列表。 (tablesBean 和 createTableBean 是请求范围)。我遵循 BalusC 教程 http://balusc.blogspot.com/2006/06/ using-datatables.html 延迟初始化 getter 中的表列表。据我所知,如果我的bean是请求范围的,那么在请求完成后不应该被销毁吗?导航来自tables.jspx -->createTable.jspx -->表.jspx。我希望在创建新表后返回到显示新表和新表的表列表。请帮助我理解我做错了什么。
这是我的代码,它返回 getter 中的表列表(简化):
public List getTables(){
if(tables==null){ //lazy initialization for a request bean as recommended by BalusC
//Return list of tables
}
但是如果我更改此行 if(表==null)
对于 if(tables==null ||FacesContext.getCurrentInstance().getRenderResponse())
当我从 createTable.jspx 返回时,我的列表被实现,当 bean 处于会话范围内时,建议进行更改,但这给我的 dataPaginator 和 sortColumn 函数带来了一个问题(因为当我按列对列表进行排序时,它从数据库返回新鲜数据,它返回错误的行进行编辑,因为我在每行中有一个用于编辑和删除的链接)
I have a page tables.jspx that shows a dataTable of all tables and has a link to createTable.jspx; when I create a new table it returns to tables.jspx but it doesn't show the list with the new table. (tablesBean and createTableBean are request scope). I follow the BalusC tutorial http://balusc.blogspot.com/2006/06/using-datatables.html initializing the list of tables in the getter lazily. As far as I now if my bean is request scoped shouldn't be destroyed after the request is finished?. The navigation is from 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):
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 lineif(tables==null)
for 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您没有发布代码,所以我将使用您上面链接的教程来解释可能发生的情况...
您是正确的,请求作用域 bean
tables
将在这里创建和销毁两次,但是每次构造它时都会调用上面列出的方法。这将根据数据库中的当前数据重新初始化表。如果
createTable.jspx
应该修改数据库中的数据,那么这些更新可能不会发生,或者新数据会被您的请求 bean 过滤掉。Because you didn't post code, I will use the tutorial you linked above to explain what might be happening...
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. 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.