1

I've the following primefaces component, it should just load images that are under /WEB-INF/Resource/{1.png,2.png,3.png,4.png}.

<p:ring id="weatherForecasts" value="#{eventPageCreatorBean.weatherForecasts}" var="weatherForecast" styleClass="image-ring" easing="easeInOutBack">
    <p:panelGrid columns="1">
        #{weatherForecast.forecastStart}
        <p:graphicImage id="img" name="/WEB-INF/Resources/images/#{weatherForecast.weatherCondition.code}.png" />
        #{weatherForecast.forecastEnd}
    </p:panelGrid>
</p:ring>

By checking on the source code from the browser I get this path:

/meteocal-web/javax.faces.resource//WEB-INF/Resources/images/1.png.xhtml

Anyone know how to solve it?

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
LNRD.CLL
  • 385
  • 1
  • 5
  • 19
  • [What is the JSF resource library for and how should it be used?](http://stackoverflow.com/q/11988415/1391249). (Store them into a folder named `resources` under the root of your application). – Tiny Jan 24 '15 at 17:16

1 Answers1

1

In JSF2, all your web-resources files like CSS, images or .js files, can be put in a resources folder, under the root of your web application (same level as WEB-INF).

>webapp
   |
   -->resources
   |      |
   |      -->images
   |           |
   |           1.png
   -->WEB-INF

Then you will be able to refer to the corresponding folder as library:

<p:graphicImage id="img" 
                library="images" 
                name="#{weatherForecast.weatherCondition.code}.png}" />
Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
  • Thanks for your help, I try with this solution but it doesn't work now there is an error as: [Error] Failed to load resource: the server responded with a status of 404 (Not Found) (RES_NOT_FOUND, line 0) I've tried either with or without the second } . – LNRD.CLL Jan 24 '15 at 10:44
  • It should be working. Are you sure your `code` is a valid value for an existing picture – Konstantin Yovkov Jan 24 '15 at 11:43
  • I wouldn't advocate the word "images" as library name. See also http://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used – BalusC Jan 25 '15 at 22:43