当我在URL中有其他文件夹时,无法加载primefaces默认主题

时间:2015-01-31 04:33:23

标签: maven jsf-2 primefaces themes

这是POM文件

<dependency>
    <groupId>org.primefaces.extensions</groupId>
    <artifactId>all-themes</artifactId>

Web.xml中

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>aristo</param-value>

在主页http://localhost/helloworld/search.faces上,primefacs主题加载

带有primefaces样式表的生成页面是

    <?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"><head><link type="text/css" rel="stylesheet" href="/helloworld/javax.faces.resource/theme.css.faces?ln=primefaces-aristo" /><link rel="stylesheet" media="screen" type="text/css" href="/helloworld/javax.faces.resource/primefaces.css.faces?ln=primefaces&amp;v=5.0" /><script type="text/javascript" src="/helloworld/javax.faces.resource/jquery/jquery.js.faces?ln=primefaces&amp;v=5.0"><!--

//--></script><script type="text/javascript" src="/helloworld/javax.faces.resource/primefaces.js.faces?ln=primefaces&amp;v=5.0"><!--

//--></script><script type="text/javascript" src="/helloworld/javax.faces.resource/jquery/jquery-plugins.js.faces?ln=primefaces&amp;v=5.0"><!--

//--></script>

但是当我访问一个文件夹的后续页面时 http://localhost/helloworld/app/welcome.faces,主题未应用。为主题文件生成的URL是添加url中的额外文件夹,因此无法找到导致主题未加载的主题文件。我应该怎么做才能将额外的文件夹添加到primefaces主题网址...

生成的页面是

    <?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"><head><link type="text/css" rel="stylesheet" href="/helloworld/app/javax.faces.resource/theme.css?ln=primefaces-aristo" /><link rel="stylesheet" media="screen" type="text/css" href="/helloworld/app/javax.faces.resource/primefaces.css?ln=primefaces&amp;v=5.0" /><script type="text/javascript" src="/helloworld/app/javax.faces.resource/jquery/jquery.js?ln=primefaces&amp;v=5.0"><!--

    //--></script><script type="text/javascript" src="/helloworld/app/javax.faces.resource/jquery/jquery-plugins.js?ln=primefaces&amp;v=5.0"><!--

//--></script><script type="text/javascript" src="/helloworld/app/javax.faces.resource/primefaces.js?ln=primefaces&amp;v=5.0"><!--

//--></script>

在web.xml中提到的xhtml中没有与主题相关的代码,在POM文件中有所有主题。

welcome.xhtml和search.xhtml是相同的,这里是片段

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    template="/WEB-INF/layouts/standard.xhtml">

<ui:define name="title">
</ui:define>

standard.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:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">....

问题摘要 如果页面中生成的网址 /helloworld/search.faces /helloworld/javax.faces.resource/primefaces.js.faces?ln=primefaces&amp;v=5.0" ...并且主题加载正常。

当网址是(深度为一个文件夹)主题未加载 /helloworld/app/welcome.faces 时,页面中生成的路径为href="/helloworld/app/javax.faces.resource/theme.css?ln=primefaces-aristo ...,请参阅应用添加的目录....这导致此资源的404错误,因为它无法找到它。

有没有办法控制生成的primefaces主题路径?

1 个答案:

答案 0 :(得分:0)

进一步挖掘其余的配置文件。在servlet上下文中添加了以下行。

<!-- Enable processing of JSF 2 resource requests. For example: /webflow-primefaces-showcase/app/javax.faces.resource/jsf.js?ln=javax.faces   -->

<faces:resources />

现在主题正在应用而没有任何问题。感谢所有插话的人。