导航规则/案例问题

时间:2013-05-05 11:30:56

标签: java jsf java-ee primefaces jboss7.x

我使用Eclipse Juno,JSF和PrimeFaces(OS Debian)创建了简单的动态Web项目。我在JBoss AS 7.1服务器上部署了我的应用程序(独立)。有免费页面:索引,添加和联系。我的导航规则是:从索引到添加和联系,从添加到索引和联系,从联系到索引和添加。 Everythings工作得很好但是从添加和联系页面我不能去索引。仅当我刷新webbrowser(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>


faces-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>

1 个答案:

答案 0 :(得分:1)

如果您使用普通链接进行简单导航,则会跳过很多问题。

导航规则机制在用于创建购物车等流程时更有用。像菜单这样的简单导航不应该使用导航规则,只需将菜单列为链接列表,就不需要为此创建操作方法。

此外,如果您在bean中使用@ManagedBean@SessionScoped注释,则无需在faces-config.xml中声明它,注释将用于替换XML配置。在您的情况下,faces-config.xml实际上是将您的bean设置为RequestScoped

相关:

When should I use h:outputLink instead of h:commandLink?