views:

25

answers:

1

I have got a situation where I have list of records say 10,000, I am using datatable and I am using paging,(10 records per display). I wanted to put put that list in the session as:

facesContext........put("mylist", mylist);

And in the getters of the mylist, I have

public List<MyClass> getMyList() {
    if(mylist== null){

        mylist= (List<MyClass>) FacesContext......getSessionMap().get("mylist");
    }

    return mylist;
}

Now the problem is whene ever i click on paging button to go to second page, only the first records are displayed, I know i am missing some thing, and I have few questions:

Is the way of putting the list in session correct. Is this the way I should be calling the list in my case.

Thnaks in advance...

+1  A: 

Something entirely different: I strongly recommend to not put those 10.000 records in the session scope. That is plain inefficient. If 100 users are visiting your datatable, those records would be duplicated in memory for every user. This makes no sense. Just leave them in the database and write SQL queries accordingly that it returns exactly the rows you want to display per request. That's the job the DB is designed for. If the datamodel is well designed (indexes on columns involved in WHERE and if necessary ORDER BY clauses), then it's certainly faster than hauling the entire table in Java's memory for each visitor.

You can find more insights and code examples in this article.

BalusC
Thks Balusc, one more question, even if I limit the number of rows to be fetched from database to 50 lets say. And lets say my maximum users are also below 10.If I am using pagination, i.e 10 records per page, clicking the next paging button will result the list to be empty rt?How do I overcome this? I cannot implement TOmaHawk's <t:saveState> property.Thanks.
Then either fix the problem causing that you cannot implement it so that you can implement it anyway, *or* put the bean in the session scope. The only caveat is that this reflects all tabs/windows in the same session. This may be a showstopper in some cases.
BalusC