2012-03-02 88 views
0

我有一個JSF項目,我已經有一個工作正常的index.xhtml頁面。當我嘗試添加另一個XHTML頁面時,由於某種原因,它沒有連接到我的會話範圍的託管bean。我在我的新頁面添加代碼,但它不像我的index.xhtml。我甚至複製並粘貼來自索引的代碼,但它仍然不起作用。有什麼想法嗎?JSF新網站創建

下面是一些我在我的新的一頁代碼:

Amount: <h:inputText value="#{transactionBean.amount}" style="color: Yellow; background: Teal;"/> 
Price <h:inputText value="#{transactionBean.pricePaid}" style="color: Yellow; background: Teal;"/ 

這裏是我的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
    <context-param> 
     <param-name>javax.faces.PROJECT_STAGE</param-name> 
     <param-value>Development</param-value> 
    </context-param> 
    <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>/faces/*</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
    <welcome-file-list> 
     <welcome-file>faces/index.xhtml</welcome-file> 
    </welcome-file-list> 
</web-app> 
+0

請具體說明。什麼「不起作用」?瀏覽器或server.log中的任何錯誤?沒有呈現HTML? – 2012-03-02 20:22:03

+0

不會有任何錯誤,它不顯示任何東西,它不顯示任何東西。只有數量和價格顯示在頁面上。沒有輸入文本或其他任何東西 – apoellitsi 2012-03-02 20:25:49

+0

原因可能是第二頁未被faces servlet處理。瀏覽器源代碼中有什麼? – 2012-03-02 20:30:12

回答

1

你映射/faces/*而不是*.xhtml臉上的servlet。這意味着您需要在URL中包含/faces路徑以獲取運行faces servlet。

所以,你不應該由

http://localhost:8080/SharePortfolioJSF/companies.xhtml

而是由

http://localhost:8080/SharePortfolioJSF/faces/companies.xhtml

好多打開網頁,不過,是剛剛使用*.xhtml作爲faces servlet的URL模式,這樣你就不需要擺弄虛擬路徑。

<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> 
<welcome-file-list> 
    <welcome-file>index.xhtml</welcome-file> 
</welcome-file-list> 

(注意<session-timeout> 30分鐘,你是默認已經,只是將其刪除)

+0

是的工作非常感謝你的幫助! – apoellitsi 2012-03-02 20:47:23

+0

沒問題;-)! – 2012-03-02 20:59:40

+0

不客氣。 – BalusC 2012-03-02 21:00:49