Reputation: 356
I have a Session Scoped managed bean that backs my web-app. In this web-app I would like to have the ability for the user to execute a URL containing a user id and a date. This will then trigger a method in the managed bean, and jump the web-app to that user id and date.
The easy answer would be to put the code for extracting parameters from the URL in the constructor of the managed bean. But the problem lies in the fact that it is Session Scoped, so the constructor is only called on initial load. If the user opens the web-app and manipulates it, then executes the URL with new parameters, there is no way for the constructor to be called.
Is there some way that I can execute a method on a Managed Bean every time the applications URL is executed (every time the page is loaded) regardless of Session state?
Upvotes: 2
Views: 1468
Reputation: 1109745
It's possible by hacking the job into a getter which is called by the view, but no, you really don't want to have it. A session scoped bean is shared between all browser windows/tabs within the same session. Every change in a window/tab will affect all other windows/tabs. This may lead to "wtf?" experiences which is thus bad for general UX (User Experience) of your site.
You really need to put that bean in the request scope if you want to intercept on GET requests, or if you're using JSF 2.0, the view scope if you want to maintain the state in subsequent POST requests after the initial GET request. A session scoped bean is intented to hold session scoped data, such as the logged-in user, its preferences, etcetera. It is not intended for request scoped data such as request parameters and like.
Upvotes: 2