I am using JSF with Primefaces to load pages dynamically. all my beans are in @ViewScoped. When I navigate the beans are not destroyed.
Here is my code samples
My template
<ui:include src="topbar.xhtml" />
<ui:include src="leftmenu.xhtml" />
<div id="layout-portlets-cover" class="fontRegular">
<ui:insert name="content">
Template
</ui:insert>
</div>
<h:form id="menuform">
<ps:menu id="sm_leftmenu">
<p:submenu id="sm_master" label="#{bundle.Master}" icon="icon-database" >
<p:menuitem value="#{bundle.Company}" action="#{homePageBean.handleCommandLink()}" update=":content" icon="">
<f:param name="centerSrc" value="/master/Company.xhtml" />
</p:menuitem>
<p:menuitem value="#{bundle.Customer}" action="#{homePageBean.handleCommandLink()}" update=":content" icon="">
<f:param name="centerSrc" value="/master/Customer.xhtml" />
</p:menuitem>
<p:menuitem value="#{bundle.Supplier}" action="#{homePageBean.handleCommandLink()}" update=":content" icon="">
<f:param name="centerSrc" value="/master/Supplier.xhtml" />
</p:menuitem>
<p:menuitem value="#{bundle.Employee}" action="#{homePageBean.handleCommandLink()}" update=":content" icon="">
<f:param name="centerSrc" value="/master/Employee.xhtml" />
</p:menuitem>
<p:menuitem value="#{bundle.CategoryWork}" action="#{homePageBean.handleCommandLink()}" update=":content" icon="">
<f:param name="centerSrc" value="/master/CategoryWork.xhtml" />
</p:menuitem>
</p:submenu>
</ps:menu>
</h:form>
The homepagebean just returns the URL set through f:param
Only the homepagebean is @SessionScoped otherwise all the other beans in the application are @ViewScoped
I also tried using a navigation rule in faces-config as below but the result is the same.
<managed-bean>
<managed-bean-name>HomePageBean</managed-bean-name>
<managed-bean-class>Utility.HomePageBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/Home.xhtml</from-view-id>
<navigation-case>
<from-action>#{homePageBean.handleCommandLink}</from-action>
<to-view-id>>/Home.xhtml</to-view-id>
<redirect></redirect>
</navigation-case>
</navigation-rule>