Reputation: 3
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
Upvotes: 0
Views: 2573
Reputation: 597106
@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)
Upvotes: 1