My managed bean used to be @ViewScoped
and I used a @PostConstruct
annotated method to situate various functions that I wanted performed each time the page is refreshed via the browser URL. However, the page requires query string parameter processing and I needed to use some AJAX and then redirect to the same page after the AJAX so, to avoid reconcatenating the query string params from the cache into the URL string, I changed the scope to @SessionScoped
so that I can just do
FacesContext.getCurrentInstance().getExternalContext().redirect("mypage.jsf");
and the session parameters that would need to be reloaded from the query string if it were @ViewScoped could just stay there. However, the problem is that the @PostConstruct method, among other things that are OK to be done only at the start of a session, does make an EJB call that should be executed on each page reload, regardless of the scope. For form submissions it is easy because I just call that EJB method in the managed bean method that the form submission calls but the problem is that it doesn't get run if the user hits refresh in the browser like it did in @ViewScoped.
Is there any way for me to keep the best of both scopes, IOW to retain the already processed query string params in the cache without having to reprocess them, like @SessionScoped affords me to while at the same time have a method that is invoked on every page reload and not just when the managed bean lifecycle begins?
I understand I could go back to @ViewScoped and reconcatenate all the query string params after mypage.jsf
in the code sample above but that seems too manual. I was hoping there was a shortcut in JSF.