List Info

Thread: request scope+getter+caching = small problem => need advice




request scope+getter+caching = small problem => need advice
user name
2007-09-24 08:38:15
Hi all,
I';m looking of advice on a problem I have with a managed bean in request scope.

The bean has a List<RunninTask>; which I retrieve from the a database, I wish to cache this locally in the to avoid hitting the db multiple times. Perfectly normal.

Some code, the getter:

&nbsp;   public List<RunningTask&gt; getRunningTasks(){
&nbsp; &nbsp;   ;  if(rtCache == null){
&nbsp; &nbsp; &nbsp;   ; &nbsp;  if(showAllJobs){
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  rtCache = runningTasksDao.getAllRunningTasks(excludeRecalcJobs);
 &nbsp; &nbsp;   ; &nbsp; &nbsp; }
 &nbsp; &nbsp;   ; &nbsp; &nbsp; else{
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  rtCache = runningTasksDao.getRunningTasks(startDate, endDate, excludeRecalcJobs);
&nbsp;   ; &nbsp; &nbsp; &nbsp;  }
 &nbsp; &nbsp;   ; &nbsp; &nbsp; Collections.sort(rtCache);
 ; &nbsp; &nbsp; &nbsp; }
 &nbsp; &nbsp;   ; return rtCache;
 &nbsp;  }

The problem is that I have two boolean properties set from the GUI (excludeRecalcJobs and showAllJobs) which are passed as parameters to the DAO, it seems the getRunningTasks() method gets called early on in the lifecycle during the post back, before the boolean properties are set. Which results in the cache being initialized before the the booleans are set :(

The only solutions I can think of are 1 putting the bean in session scope, and 2 commenting out the outer if. Neither of which I'm happy with.

Any ideas?

Cheers,
 ;Mike

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )