Reputation: 23
How can I use the resource variable to create a dynamic path?
<ui:repeat value="#{backgroundImageBean.images}" var="image">
<p:graphicImage value="#{resource['/path/#{image}']}"
style="width: 100%; height: 100%" />
</ui:repeat>
Thanks
Upvotes: 2
Views: 975
Reputation: 1109655
Just use name
attribute instead of value
attribute. The value
attribute takes an URL while the name
attribute takes the sole resource name already. It's then under the covers resolved the same way as #{resource[name]}
.
<p:graphicImage name="path/#{image}" />
Upvotes: 4
Reputation: 11742
Your problem can be solved in one of the two ways:
'/path/'
part into your model so that #{image}
would return the full path to the resource;Create an alias for the to-be-generated image path using <ui:param>
and use it when accessing the resource:
<ui:repeat value="#{backgroundImageBean.images}" var="image">
<ui:param name="path" value="/path/#{image}" />
<p:graphicImage value="#{resource[path]}" />
</ui:repeat>
If you're insisting on doing the logic without using a parameter and your environment supports EL 2.2+ then you can use String#concat()
in your resource expression:
#{resource['/path/'.concat(not empty image ? image : '')}'
Upvotes: 2