Using ui:include with View Scoped beans
I am only new to JSF but I have found myself stuck on a problem for quite some time and I am not sure if it is purely down to lack of knowledge to the lifecycle of the view scope.
The scenario is that I want to use a view scoped bean to store the state of a component. There is one property on the bean that I want to read out and that is of the path for the currently displayed page (path to the file such as /blah/foo.xhtml). I use it in the following manner:
There are some buttons on the page that change the viewPage property on MyViewBean which would cause the value of viewPage to change and thus a different component would be rendered. This is because I don't know which page to display at design time.
The behaviour that ensured was that no matter what buttons you clicked (made sure the request was not causing a redirect) the MyViewBean bean was being created every single request. I even created a @PostConstruct annotated method, set a breakpoint there and could confirm a new view scoped variable was being created every request.
If I changed MyViewBean to be SessionScoped, it would behave as expected however I wanted the behaviour to be view based so two browser windows could co-exist in which the view scope fits the bill!
After removing the , using the debugger, I could confirm that the view scoped bean being was being managed correctly and that a new instance was not being created every request as expect.
After some digging around, it looks like my issue starts with the way the order the view scope is set in the restore view phase of JSF. Turns out, the EL expressions are executed before JSF restores the view scope map. The consequence is that when the FaceletViewHandlingStrategy.buildView() is run, only session scoped beans are available and thus JSF creates a new view scoped object and uses that.
Is this the intended behaviour of view scopes or should I be looking at creating my own custom scope?
Thanks in advance,
Message was edited by: mdergacz