【问题标题】:graphicImage not correct url [duplicate]graphicsImage 不正确的网址 [重复]
【发布时间】:2015-01-24 09:05:03
【问题描述】:

我有以下 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

有人知道怎么解决吗?

【问题讨论】:

标签: jsf url primefaces graphicimage


【解决方案1】:

在 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}" />

【讨论】:

  • 感谢您的帮助,我尝试使用此解决方案,但它现在不起作用,出现以下错误:[错误] 加载资源失败:服务器响应状态为 404(未找到) (RES_NOT_FOUND,第 0 行)我尝试过使用或不使用第二个 } 。
  • 它应该可以工作。您确定您的code 是现有图片的有效值吗
  • 我不提倡将“图像”一词作为库名称。另见stackoverflow.com/questions/11988415/…
猜你喜欢
  • 1970-01-01
  • 2014-03-20
  • 2015-07-26
  • 1970-01-01
  • 1970-01-01
  • 2017-04-18
  • 2020-12-22
  • 2020-07-13
  • 2014-10-10
相关资源
最近更新 更多