I would like to have a Ajax-Based Tabbed interface in my website.
I would also like to have a bean for each of the tabs.
These beans are expected to be "born" when entering the tab and "die" when leaving the tab.
Important - The switch between tabs must be an AJAX event and not a full page redraw.
I thought @ViewScoped
is the appropriate scope for this type of behaviour but I am stuck on the issue of killing the bean when leaving a tab. To my best knowledge, a @ViewScoped
bean will only die on a redirect/navigation event.
Is there a proper way to make the @ViewScoped
bean die? Should I use a different scope?
Thanks!
UPDATE
Reading BalusC's answer on this question is good indication:
A view scoped bean lives as long as you interact with the same view (i.e. you return void or null in bean action method). When you navigate away to another view, e.g. by clicking a link or by returning a different action outcome, then the view scoped bean will be trashed by end of render response and not be available in the next request.
So, according to this, I could return a different outcome from an action method and make the @ViewScoped
bean die.
But to do this I have to disable navigation after an outcome from an action method (JSF 2 implicit navigation) and I don't know how to do that (or if that's the right way to achieve my goal)