graphicImage不正确的网址

时间:2015-01-24 09:05:04

标签: jsf url primefaces graphicimage

我有以下的primefaces组件,它应该只加载/WEB-INF/Resource/{1.png,2.png,3.png,4.png}下的图片。

<p:ring id="weatherForecasts" value="#{eventPageCreatorBean.weatherForecasts}" var="weatherForecast" styleClass="image-ring" easing="easeInOutBack">
    <p:panelGrid columns="1">
        #{weatherForecast.forecastStart}
        <p:graphicImage id="img" name="/WEB-INF/Resources/images/#{weatherForecast.weatherCondition.code}.png" />
        #{weatherForecast.forecastEnd}
    </p:panelGrid>
</p:ring>

通过检查浏览器中的源代码,我得到了这条路径:

/meteocal-web/javax.faces.resource//WEB-INF/Resources/images/1.png.xhtml

任何人都知道如何解决它?

1 个答案:

答案 0 :(得分:2)

在JSF2中,您的所有Web资源文件(如CSS,图像或.js文件)都可以放在Web应用程序根目录下的resources文件夹中(与WEB-INF相同) 。

>webapp
   |
   -->resources
   |      |
   |      -->images
   |           |
   |           1.png
   -->WEB-INF

然后,您将能够将相应的文件夹称为library

<p:graphicImage id="img" 
                library="images" 
                name="#{weatherForecast.weatherCondition.code}.png}" />