2014-11-22 63 views
0

我是JSF和JSF的新手標籤在我的First.xhtml中無法正常工作。 我的web.xml文件中有如下代碼JSF標記未呈現爲HTML

<?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_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>JSFNewProject</display-name> 
    <welcome-file-list> 
    <welcome-file>index.jsp</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> 
</web-app> 

代碼在我faces.config文件

<?xml version="1.0" encoding="UTF-8"?> 

<faces-config 
    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-facesconfig_2_0.xsd" 
    version="2.0"> 
</faces-config> 

My code in the First.xhtml is 

<?xml version="1.0" encoding="UTF-8"?> 

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://xmlns.jcp.org/jsf/core" 
    xmlns:h="http://xmlns.jcp.org/jsf/html"> 
    <title>Facelet</title> 
    <h:body> 
    <h2>hi Amit</h2> 
    <h:form> 
    <h:outputLabel id="firstNameOutputId" value="firstname:" /> 
    <h:inputText id="firstNameInputId" value="#{userRegistration.firstName}"> </h:inputText> 

    <h:outputLabel id="lastNameOutputId" value="lastname:" /> 
    <h:inputText id="lastNameInputId" value="#{userRegistration.lastName}"> </h:inputText> 

    <h:outputLabel id="ageOutputId" value="Age" /> 
    <h:inputText id="ageInputId" value="#{userRegistration.age}"> </h:inputText> 

    <h:outputLabel id="dobOutputId" value="DoB" /> 
    <h:inputText id="dobInputId" value="#{userRegistration.dob}"> </h:inputText> 

    <h:outputLabel id="cityOutputId" value="City" /> 
    <h:inputText id="cityInputId" value="#{userRegistration.city}"> </h:inputText> 

    <h:outputLabel id="salaryOutputId" value="Salary" /> 
    <h:inputText id="salaryInputId" value="#{userRegistration.salary}"> </h:inputText> 

    <h:commandButton id="userRegistrationCmdBtnId" value="Register" action="userRegistration.processRegistration"> 
    </h:commandButton> 
    </h:form> 
    </h:body> 
</html> 

我已經嘗試了像改變URL映射爲/ faces/*並且包含罐許多選項在WEB-INF/lib下,但都沒用...... 幫助正在徵求....謝謝

回答

0

你應該使用JSF標準標籤(h:headh:body),我在下面給出一個例子。

<?xml version="1.0" encoding="UTF-8"?> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:p="http://primefaces.org/ui"> 
    <h:head> 
     <f:facet name="first"> 
      <meta http-equiv="Content-Type" 
        content="text/html; charset=UTF-8" /> 
      <meta name="viewport" 
        content="user-scalable=no, 
        width=device-width, 
        initial-scale=1.0, 
        maximum-scale=1.0"/> 
     </f:facet> 

     <title>layout</title> 
    </h:head> 

    <h:body> 
     <p:layout fullPage="true"> 
      <p:layoutUnit position="north" size="50"> 
       <h:outputText value="Top content." /> 
      </p:layoutUnit> 
      <p:layoutUnit position="south" size="100"> 
       <h:outputText value="Bottom content." /> 
      </p:layoutUnit> 
      <p:layoutUnit position="west" size="300"> 
       <h:outputText value="Left content" /> 
      </p:layoutUnit> 
      <p:layoutUnit position="east" size="200"> 
       <h:outputText value="Right Content" /> 
      </p:layoutUnit> 
      <p:layoutUnit position="center"> 
       <h:outputText value="Center Content" /> 
      </p:layoutUnit> 
     </p:layout> 
    </h:body> 
</html> 

<h:head>是JSF標籤(與JSF 2.0中引入的)來處理頁面的<head>一部分。擁有這樣的JSF標籤的興趣是這個頭成爲你的JSF組件樹的一部分,因此,你可以在你的Java代碼中操作它。