2013-05-05 25 views
0

我使用Eclipse Juno,JSF和PrimeFaces(OS Debian)創建了簡單的動態Web項目。我在JBoss AS 7.1服務器(獨立)上部署了我的應用程序。有免費網頁:索引,添加和聯繫。我的導航規則是:從索引到添加和聯繫,從添加到索引和聯繫人,從聯繫人到索引和添加。 Everythings運作良好,但從添加和聯繫頁面我不能去索引。僅當我刷新web瀏覽器(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:

在.xhtml頁面菜單
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> 

代碼:

<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

如果您使用簡單的導航鏈接樸素你會跳過了很多問題。

例如,導航規則機制在用於創建像購物車之類的流時更加有用。像菜單這樣的簡單導航不應該使用導航規則,只需將菜單設置爲鏈接列表即可,無需爲此創建操作方法。另外,如果您在bean中使用@ManagedBean@SessionScoped註釋,則不需要在faces-config.xml中聲明該註釋,但註釋旨在替換XML配置。在你的情況下,faces-config.xml實際上是將你的bean設置爲RequestScoped

相關:

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

+0

雖然你實際上並沒有回答任擇議定書的問題,在所有的帖子,這基本上我會寫文字,所以肯定+1!但我會解釋一下OP所要求的。 – skuntsel 2013-05-05 16:27:39

+0

@skuntsel謝謝!是的,我認爲這是OP需要聽到的情況,也許不是他想要的 - 可隨意編輯或添加自己的答案,以便我可以+1! :) – elias 2013-05-05 17:48:07