2014-09-29 66 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

相关问题