Primefaces资源未加载

时间:2017-03-13 09:01:20

标签: jsf primefaces jsf-2 resources tomee

我使用Primefaces 5.3和TomEE,但是当我访问我的页面时,PF资源没有被加载,我收到以下错误:

$ is not defined
PrimeFaces is not defined

即使我访问资源URL,我也会收到以下错误 网址:

http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo

错误:

XML Parsing Error: no root element found Location: http://localhost:8080/Myapp/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo Line Number 1, Column 1

我的页面:

<?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://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

<h:head>

</h:head>

<f:view>
    <p:growl id="notificationMessage" showDetail="true" />
    <p:panel id="basic" header="Basic" footer="Movie Details" style="margin-bottom:20px">
        <h:panelGrid columns="1" cellpadding="10">

            <p:outputLabel  for="mbbData" value="Data Value: " />
            <p:inputText id="mbbData" value="#{mbbDataInputController.mbbData}" required="true" />

            <p:commandButton action="#{mbbDataInputController.addMbb}" />


        </h:panelGrid>
    </p:panel>


</f:view>
</html>

的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"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID"
         version="3.0">

    <display-name>my-service</display-name>


    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>
            WEB-INF/faces-config.xml
        </param-value>
    </context-param>

    <!-- Faces Servlet -->
    <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>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>


    <servlet>
        <servlet-name>rest-servlet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.huawei.myapp.service</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>rest-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

我还尝试将以下内容添加到页面头部:

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />

但它不起作用。

另请注意,在调试PrimeResourceHandler类时,正在创建资源,资源路径位于正确的jar中。

1 个答案:

答案 0 :(得分:0)

好的,我发现问题和解决方案如下。

<强>问题:

问题是我使用两个servlet,javax.faces.webapp.FacesServlet用于JSF,org.glassfish.jersey.servlet.ServletContainer用于REST Web服务。当我请求reource文件时,实际上Jersey servlet将为我服务而不是面向servlet。

<强>解决方案:

我将web.xml网址映射更改为:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/javax.faces.resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>rest-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>