I save images, css, and javascript (the folders has the same name) files in a resource folder in the webapp root. Should I be using URLs to get show the image in for example a graphicImage tag or should I be using the #{resources:libraryName..}
?
Asked
Active
Viewed 153 times
3

LuckyLuke
- 47,771
- 85
- 270
- 434
1 Answers
4
Just use the therefor provided <h:outputStylesheet>
, <h:outputScript>
and <h:graphicImage>
components wherein you specify a path relative to the resources folder in the name
attribute:
<h:outputStylesheet name="css/style.css" />
<h:outputScript name="js/script.js" />
<h:graphicImage name="images/logo.png" />
JSF will worry about setting the right URL.
The #{resource}
syntax is only necessary inside CSS files to reference background images.
See also:
-
Ah, okey. So thats what the #{resource} is for. Thank you. – LuckyLuke Dec 16 '11 at 18:31
-
But what if the image is made with regular img-tag (its a template). Should I change to using the JSF equivalent? If not do I need to append "resources" in front off css/js/images? – LuckyLuke Dec 16 '11 at 18:33
-
You should definitely change it by the therefor intended JSF component. Otherwise you indeed need to bring in some ugly boilerplate code to get the relative URL right for every single instance of the raw HTML element. – BalusC Dec 16 '11 at 18:35
-
Not when the JSF page is by itself inside a folder. You'd need to change the image URL to point to a domain-relative URL `
`. Those JSF components removes exactly this boilerplate and worriness from your hands and you also end up with less code. – BalusC Dec 16 '11 at 18:43
-
Oh, I see. Great help as allways! – LuckyLuke Dec 16 '11 at 18:45