【问题标题】:JSF Tags not rendered as HTMLJSF 标记未呈现为 HTML
【发布时间】:2015-01-20 08:50:48
【问题描述】:

我是 JSF 新手,我的 First.xhtml 中的 JSF 标记不起作用。 我的 web.xml 文件有以下代码

<?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 中包含 Jars,但没有用... 正在寻求帮助....谢谢

【问题讨论】:

    标签: jsf


    【解决方案1】:

    你应该使用 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>
    

    &lt;h:head&gt; 是一个 JSF 标记(在 JSF 2.0 中引入),用于处理页面的 &lt;head&gt; 部分。拥有这样的 JSF 标记的好处在于,这个头成为 JSF 组件树的一部分,因此,您可以在 Java 代码中操作它。

    【讨论】:

      猜你喜欢
      • 2011-01-13
      • 1970-01-01
      • 2012-01-26
      • 1970-01-01
      • 2011-03-20
      • 2013-08-19
      • 1970-01-01
      • 2012-12-08
      • 2013-10-06
      相关资源
      最近更新 更多