Quoting from this nice article,
The new view scope should solve exactly those issues. A @ViewScoped bean will live as long as you're submitting the form to the same view again and again. In other words, as long as when the action method(s) returns null or even void, the bean will be there in the next request. Once you navigate to a different view, then the bean will be trashed.
And these questions come into mind:
- If my current view is
index.xhtml
, and if I specify explicitlyreturn "index";
or<h:commandButton action="index.xhtml" ..>
, which is basically returning to the same view, the bean will be recreated again .. why? - Can a viewscoped bean survive a redirection?
- And if it can, how can I specify it? I can't imagine doing something like
return "?faces-redirect=true"
or<h:commandButton action="?faces-redirect=true" ..>
, and yes, I would like to skip defining the navigation infaces-config.xml
using the<redirect/>
.