0

我在页面上显示图像时遇到问题:

<h:graphicImage value="resource:///image/actors/#{imageBean.source}" alt="pic" />

#{imageBean.source} = "image.jpg"的结果在哪里

结果:

[13:10:14.445] GET http://localhost:7001/webapp-core/faces/image.jpg [HTTP/1.1 404 Not Found 578ms]

显然不起作用,但我不知道正确的方法是什么。

我尝试了很多变化,fe:

- <h:graphicImage value="#{resource['image/actors/imageBean.source']}" alt="pic" />
- <h:graphicImage value="resource:///#{imageBean.source}" alt="pic" />
- <h:graphicImage value="#{resource['image/akteurs/imageBean.source']}" alt="pic" />

我的主要问题是如何让 #{imageBean} 在资源上下文中工作。

正确的路径是:

[13:37:28.935] GET http://localhost:7001/webapp-core/faces/ javax.faces.resource /image/actors/image.jpg [HTTP/1.1 200 OK 31ms]

设置 web.xml:

<context-param>
  <param-name>org.richfaces.resourceOptimization.enabled</param-name>
  <param-value>false</param-value>
</context-param>
4

1 回答 1

2

The resource:// URI is not valid in this context. It has an entirely different purpose. To reference JSF resources in the view, you should be using #{resource}.


My main problem is how to get #{imageBean} working inside the resource context.

You can just inline it by creating another string variable in EL beforehand using JSTL <c:if>:

<c:set var="identifier" value="image/actors/#{imageBean.source}" />
<h:graphicImage value="#{resource[identifier]}" alt="pic" />

Or, if your environment supports EL 2.2, make use of String#concat():

<h:graphicImage value="#{resource['image/actors/'.concat(imageBean.source)]}" alt="pic" />
于 2013-09-16T13:21:23.193 回答