W vd L
W vd L

Reputation: 625

How to get a variable image in richfaces from resources

I have a problem showing images on my page:

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

where the result of #{imageBean.source} = "image.jpg"

result:

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

Doesn't obviously work, but i dont know what the correct way would be.

I have tried many variations, f.e.:

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

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

The correct path is:

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

settings web.xml:

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

Upvotes: 0

Views: 648

Answers (1)

BalusC
BalusC

Reputation: 1108742

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

Upvotes: 2

Related Questions