tags:

views:

63

answers:

1

I have an @PostConstruct init() function in my backing bean that performs a lengthy database query.

The backing bean is @SessionScoped.

Every time I perform an Ajax query, I hit that init() and the database query fires off again.

Do I need to check life cycle phase in my init() before firing the database query? Or should I store the details in a more persistent object such as the current User?

Best regards, Alan

+1  A: 

@PostConstruct for @SessionScoped beans is executed only once per user session, so it is the correct place to initialize the bean. Make sure the bean is indeed in session scope, and that the multiple executions of it are not actually coming from different users (=> sessions)

Bozho
Thanks for the help -- you guys are the best. literally. Double checked SessionScoped -- good there. Dedicated development server with me as the only user. Checked the session ID - session id ("e6de4c1d14184029f952925cce79") doesn't change between first call to init() and second call to init() from Ajax request. However, value for 'this' (referring to the backing bean instance) does change. Something unexpected is happening. Thoughts?
Alan Lattimore
Hm, give us a bit more details. The faces-config, for example. Whether or not you are using CDI.
Bozho
Isolated and removed elements on the page that were creating references to a new backing bean instance. Still not sure _why_ the ajax request referenced a new backing bean instance. It's a workaround when I would rather understand but there's a lot of pressure to move forward. Thx.
Alan Lattimore
might be a bug in your JSF implementation. Try upgrading (if there's a newer version)
Bozho