2012-03-02 90 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