request scoped bean JSF
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 th开发者_运维百科at 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 line
if(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)
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. 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.
精彩评论