JSF和p:dataTable的组合

时间:2016-01-11 15:57:57

标签: jsf primefaces datatable xhtml

当我尝试使用Primefaces时,如下例(index.xhtml):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xml:lang="en" lang="en">
<h:head>
    <title>Title</title>
</h:head>
<h:body>
    <p:dataTable var="vehicle" value="#{indexController.vehicles}">
        <p:column headerText="Marke">
            <h:outputText value="#{vehicle.brand}"/>
        </p:column>
        <p:column headerText="Typ">
            <h:outputText value="#{vehicle.type}"/>
        </p:column>
    </p:dataTable>
</h:body>
</html>

数据表不会出现在网页上。但是,如果我检查HTML,我可以看到根本没有使用primefaces标签:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en"><head id="j_idt2">
    <title>Title</title></head><body>
    <p:dataTable var="vehicle" value="[Alfa Romeo asdflajeefij, AlRomeo asdflajeefij, A Romeo asdflajeefij]">
        <p:column headerText="Marke">
        </p:column>
        <p:column headerText="Typ">
        </p:column>
    </p:dataTable><ul id="javax_faces_developmentstage_messages" title="Project Stage[Development]: Unhandled Messages"></ul></body>
</html>

业务逻辑应该正常工作,因为您看到值已正确加载。

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
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>cupertino</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 个答案:

没有答案