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:

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

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

Reply via email to