JSF and Database Access

Hi all,

I have a page which uses a backing bean set up for request scope. When the page is first loaded, the backing bean is instantiated, and in its constructor I load data from a database. Because the bean is in request scope, when the user submits the for to do whatever, the backing bean is re-instantiated, so I call the database again.

For performance reasons this isnt so hot, so I change the bean to session scope. But lets say the user navigates away from the page to some other part of the webapp. Then later on, they come back to the page with results from the database. Because the bean is in the session, its constructor is not called and so I dont refresh the database results. So I have to implement a button or link so that the user can click, which calls an action where i refresh the data.... But that is not logical to the user. When they click the original link to this page they are expecting updated results. Same is true if they hit the refresh button!!

A Microsoft Webforms style isPostBack variable or method would deal with this problem brilliantly, but Ive read lots of posts saying that JSF doesnt offer anything like this...

So what I am supposed to do in this scenario?

Ant

[1240 byte] By [ant.kutscheraa] at [2007-10-2 4:38:12]
# 1

Putting logic in constructor is not a good idea especially with a request scope bean. A request scope bean constructor may fire more than once during a JSF request.

To try to answer your question, different people did different things to solve this same problem. Search this forum for "ispostback" or "postback" keywords to get some ideas. If you are using IBM implementation of JSF, you may be in luck because it was extended to support this needed post back mechanism.

nboudania at 2007-7-16 0:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...