开发者

JSF session issue

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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜