我正在使用带有Primefaces的JSF来动态加载页面。我所有的bean都在@ViewScoped中。当我浏览豆类时不会被破坏。
这是我的代码示例
我的模板
<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>
homepagebean只返回通过f:param
设置的URL只有homepagebean是@SessionScoped,否则应用程序中的所有其他bean都是@ViewScoped
我也尝试在faces-config中使用导航规则,如下所示,但结果是一样的。
<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>