2014-09-29 78 views
0

在這個小小的項目中,只有一個類RichBean.java和一個JSF文件index.html來演示在JSF中使用CDI。我的問題是關於「爲什麼在JSF的web.xml中以這種方式定義?

<welcome-file>faces/index.xhtml</welcome-file>" 

在web.xml中定義的。爲什麼是‘面孔/’?

沒有任何提及‘面孔/’目錄或配置。我覺得‘面孔’只是一個名字,可以是任何東西,但它不是這樣的。我試着將其更改爲別的東西,即「faceg」,它則不起作用。

RichBean.java

@Named 
    @SessionScoped 
    public class RichBean implements Serializable { 

    private String name; 

    @PostConstruct 
    public void postContruct() { 
     name = "John"; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 
    } 

index.xhtml

.... 
<body> 
<ui:composition template="/templates/template.xhtml"> 

    <ui:define name="title">Hello world JSF</ui:define> 

    <ui:define name="body"> 
     <fieldset style="width:500px"> 
      <legend>Helloworld using JSF and RichFaces</legend> 
      <p> 
       This example demonstrates adding ajax processing and updating to a standard JSF component. 
      </p> 

      <rich:panel header="Ajax enabled inputText"> 
       <h:form id="helloWorldJsf"> 
        <h:outputLabel value="Name:" for="nameInput"/> 
        <h:inputText id="nameInput" value="#{richBean.name}"> 
         <a4j:ajax event="keyup" render="output"/> 
        </h:inputText> 
        <h:panelGroup id="output"> 
         <h:outputText value="Hello #{richBean.name}!" 
             rendered="#{not empty richBean.name}"/> 
        </h:panelGroup> 
       </h:form> 
      </rich:panel> 
     </fieldset> 
    </ui:define> 
    </ui:composition> 
    </body> 
    </html> 

的beans.xml

<beans 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/beans_1_0.xsd"> 
    </beans> 

web.xml中。

如何配置「faces /」?我不知道如何以及爲什麼它連接到項目中的其他任何東西。

我正在學習這個演示。請幫助理解這一點。非常感謝。

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

    <!-- add a welcome-file-list entry to allow JSF pages to be used as welcome files --> 
     <welcome-file-list> 
     <welcome-file>faces/index.xhtml</welcome-file> 
     </welcome-file-list> 
    </web-app> 

回答

0

servlet類FacesServlet的開始JSF請求處理 生命週期,並且必須在web.xml來定義。 Servlet映射 標籤定義了FacesServlet應該執行的URL。 圖案/faces/*通常由JSF規範使用,但 任何其他前綴或擴展名都可能爲。該示例使用 網絡應用程序屬性版本=「2.5」這意味着我們正在使用 servlet-api版本2.5。如果你使用tomcat 6,我們需要在2.5版本中至少使用 servlet-api。與jsf 1.2相比,在 這個例子中沒有任何變化。 下面你可以看到web.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<web-app 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 web-app_2_5.xsd" 
version="2.5"> 
    <context-param> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>client</param-value> 
    </context-param> 
<display-name>HelloWorld with JSF RI 2 (Beta 2)</display-name> 
<servlet> 
<display-name>FacesServlet</display-name> 
<servlet-name>FacesServlet</servlet-name> 
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
<load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>FacesServlet</servlet-name> 
<url-pattern>/faces/*</url-pattern> 
</servlet-mapping> 
</web-app> 

您可以更改/面/ 到/ facesg/按照您的要求,它會爲你工作。

我希望它能解決您的查詢!

+0

爲什麼你使用不同的web.xml作爲例子,這與我給出的截然不同。所以你沒有用你的例子很好地解釋這個問題。請使用我的web.xml來解釋。謝謝。 – marlon 2014-09-30 04:00:05

相關問題