1

I have following audio tag in my markup:

<audio id="audio" preload="auto" hidden="true">
    <source src="#{resource['sounds:filename.mp3']}" type="audio/mpeg" />
    <source src="#{resource['sounds:filename.ogg']}" type="audio/ogg" />
    <embed src="#{resource['sounds:filename.mp3']}" hidden="true"/>
</audio>

I want to wrap this inside a custom composite component which gets the filename as an attribute.

<source src="#{resource['sounds:cc.attrs.filename.mp3']}" type="audio/mpeg" />

This is obvious not working since .mp3 now seems to be a child of filename. How do I escape the dot?

djmj
  • 5,579
  • 5
  • 54
  • 92

2 Answers2

3

Parameterize it using <ui:param>.

<ui:param name="resourceIdentifier" value="sounds:#{cc.attrs.filename}.mp3" />
<source src="#{resource[resourceIdentifier]}" type="audio/mpeg" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
2

What you want is to use is a concatenation function for Facelets.

Either create one as described here, or set up OmniFaces in your project, so you can use its nice String manipulation functions, like this:

<source src="#{resource[of:concat('sounds:', cc.attrs.filename)]}"
    type="audio/mpeg" />
Community
  • 1
  • 1
Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107