我使用 Eclipse Juno、JSF 和 PrimeFaces (OS Debian) 创建了简单的动态 Web 项目。我在 JBoss AS 7.1 服务器(独立)上部署了我的应用程序。有免费页面:索引、添加和联系。我的导航规则是:从索引到添加和联系人,从添加到索引和联系人,从联系人到索引和添加。一切运作良好,但从添加和联系页面我无法进入索引。仅当我刷新网络浏览器 (Google Chrome) 时才会出现索引页面。有人有同样的问题吗?我搜索了它,但没有找到任何解决方案。非常感谢您的帮助。这是我的文件:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>excite-bike</param-value>
</context-param>
<display-name>Example2</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
<welcome-file>add.xhtml</welcome-file>
<welcome-file>contact.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class></servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
面孔-config.xml:
<managed-bean>
<managed-bean-name>addBean</managed-bean-name>
<managed-bean-class>web.AddBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>menuBean</managed-bean-name>
<managed-bean-class>web.MenuBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>add</from-outcome>
<to-view-id>/add.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>contact</from-outcome>
<to-view-id>/contact.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/add.xhtml</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>contact</from-outcome>
<to-view-id>/contact.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/contact.xhtml</from-view-id>
<navigation-case>
<from-outcome>add</from-outcome>
<to-view-id>/add.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
MenuBean.java:
package web;
import javax.annotation.ManagedBean;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class MenuBean {
public String home(){return "home";}
public String add(){return "add";}
public String contact(){return "contact";}}
<br>
.xhtml 页面中的菜单代码:
<h:form>
<p:tabMenu activeIndex="1">
<p:menuitem value="HOME" icon="ui-icon-star"
action="#{menuBean.home()}" />
<p:menuitem value="ADDS" icon="ui-icon-document"
action="#{menuBean.add()}" />
<p:menuitem value="CONTACT" icon="ui-icon-person"
action="#{menuBean.contact()}" />
</p:tabMenu>
</h:form>