CSS图像未加载myfaces和primefaces,#{resource [' image ...']}无法正常工作

时间:2016-05-28 14:30:08

标签: css maven jsf primefaces myfaces

我尝试了很多论坛,但我没有找到解决方案来解决我的问题。 目前我在Eclipse中使用Maven项目来创建一个使用myfaces和primefaces的网站。我也在使用Apache Tomcat 8.0.28。

除了从CSS文件加载图像外,我项目中的所有内容都能正常工作。我使用(在<h:head></h:head>之间)

在我的xhtml模板文件中包含CSS
<h:outputStylesheet name="css/styles.css"/>

我的CSS在/ resources / css下正确加载。但不是里面的图像。我试过这些解决方案:

- background-image: url("#{resource['images/image.jpg']}");
- background: #FFF url(../images/image.jpg);
- background: #FFF url(../images/image.jpg.xhtml); -> works but I don't know why ??

最后一行是这样的,所以我第一次使用那个解决方案,但我为自己的图像所遇到的问题也与primefaces css图像有关......

enter image description here

注意:当我在xhtml中使用<h:graphicImage name="images/image.png">时有效!

Here is my project structure

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

<welcome-file-list>
  <welcome-file>index.xhtml</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>

<context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>resources.application</param-value>
</context-param>
<context-param>
  <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>client</param-value>
</context-param>
<context-param>
  <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
  <param-value>true</param-value>
</context-param>
<context-param>
  <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
  <param-value>true</param-value>
</context-param>
<context-param>
  <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
  <param-value>false</param-value>
</context-param>
<context-param>
  <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
  <param-value>true</param-value>
</context-param>

<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>

<context-param>
  <param-name>primefaces.THEME</param-name>
  <param-value>glass-x</param-value>
</context-param>
<security-constraint>
  <display-name>Security constraint</display-name>
  <web-resource-collection>
    <web-resource-name>Automatic SLL forwarding</web-resource-name>
    <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>

</web-app>

我的pom.xml:

<repositories>
  <repository>
    <id>prime-repo</id>
    <name>PrimeFaces Maven Repository</name>
    <url>http://repository.primefaces.org</url>
    <layout>default</layout>
  </repository>
</repositories>

<dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
 </dependency>
 <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>3.1.0</version>
 </dependency>
 <dependency>
   <groupId>javax.servlet.jsp</groupId>
   <artifactId>javax.servlet.jsp-api</artifactId>
   <version>2.3.1</version>
 </dependency>
 <dependency>
   <groupId>javax.el</groupId>
   <artifactId>javax.el-api</artifactId>
   <version>3.0.0</version>
 </dependency>
 <dependency>
   <groupId>org.primefaces</groupId>
   <artifactId>primefaces</artifactId>
   <version>5.3</version>
 </dependency>
 <dependency>
   <groupId>org.apache.myfaces.core</groupId>
   <artifactId>myfaces-api</artifactId>
   <version>2.2.10</version>
 </dependency>
 <dependency>
   <groupId>org.apache.myfaces.core</groupId>
   <artifactId>myfaces-impl</artifactId>
   <version>2.2.10</version>
 </dependency>
 <dependency>
   <groupId>org.apache.myfaces.tomahawk</groupId>
   <artifactId>tomahawk20</artifactId>
   <version>1.1.14</version>
 </dependency>
 <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
   <version>1.2</version>
 </dependency>
 <dependency>
   <groupId>org.primefaces.themes</groupId>
   <artifactId>all-themes</artifactId>
   <version>1.0.10</version>
 </dependency>
</dependencies>

<build>
  <finalName>dnsEnumArtifact</finalName>
  <plugins>
   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
       <source>1.8</source>
       <target>1.8</target>
     </configuration>
   </plugin>
 </plugins>
</build>

我不知道问题出在哪里,配置,web.xml,依赖关系,tomcat ...... 提前感谢您的帮助。

劳伦

0 个答案:

没有答案