Tim Holloway wrote:Well, first off, I feel obliged to recommend caution in using this new feature in JSF2. I saw a similar capability in Struts abused royally. There are some very useful things you can do with it, such as creating a "back" function that can return to one of a number of possible forwarding pages. But wholesale coding static views into an action processor unnecessarily hard-wires things into what was originally intended to be a more flexible framework. It also makes it harder for new people to follow the page flow, since, unlike the centralized faces-config file, there's no single place you can look to see how the views interconnect.
Regardless, I don't think a new session is being created. From what you said, you're initializing a bean before it's being constructed. That's a pretty good trick, and it implies that you're not doing what you think you're doing. It also confuses me, since I'm not sure if the bean you're referring to is the bean that contains the action processor or some other session object.
I can see where it might confuse the framework if you are navigating from within a bean instead of faces-config, but in this particular case what it sounds like is that you need to be injecting the affected bean into the bean that has the action in it so that the affected bean will have been constructed in advance. That's assuming I have any clue at all about what you're trying to do.
It also sounds like you need to read up on the JSF lifecycle (as defined for JSF 2), since you were determining the order of events by experimentation. A fundamental thing about JSF is that all the properties get validated, then set, then the action process fires, unless you explicitly short-circuit parts of this event sequence. So that much you should be able to count on.
Brendan Healey wrote:
What's happening is that in JSF 2.02-10 a backing bean declared as session scoped using
the @SessionScoped annotation (along with @ManagedBean) is treated as REQUEST SCOPED
and not session scoped. If the bean is declared in the faces-config file it works as expected.