5

I have the following tag:

<h:graphicImage value="Circle_Yellow.png" library="images" />

In my folder I have the following structure:

/resources/images/.....
/WEB-INF/....
/*.xhtml

When rendered that image shows up as:

<img src="Circle_Yellow.png">

However I do see other things using resources, for example

<script type="text/javascript" src="/www/javax.faces.resource/jquery/jquery.js.xhtmlln=primefaces"></script>

And if I go to /www/javax.faces.resource/Circle_Yellow.png?ln=images it works.

So what could I possibly be doing wrong that my library gets ignored on the h:graphicImage. Also it isn't just as an image, I have a css file that is failing too.

I'm using mojarra 2.1.16 and primefaces 3.4.1.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
casolorz
  • 8,486
  • 19
  • 93
  • 200

2 Answers2

11

The value attribute takes an URL, not the resource name. To specify the resource name, use the name attribute.

<h:graphicImage library="images" name="Circle_Yellow.png" />

See also the <h:graphicImage> tag documentation for details.


Unrelated to the concrete problem, your usage of the library attribute is not entirely right. Please carefully read What is the JSF resource library for and how should it be used? You should be using it as

<h:graphicImage name="images/Circle_Yellow.png" />
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you, I don't know how I missed the name/value thing. I'm trying to use libraries mainly as a way to not have to worry about paths for now as I am just starting this project and I'm not settled on how it is even going to get deployed. – casolorz Dec 14 '12 at 15:01
  • You're welcome. Yes, JSF2 resource libraries are the way to go. The `` is actually a leftover from JSF 1.x. – BalusC Dec 14 '12 at 15:02
-1

Try using this,

<h:graphicImage value="resources/images/Circle_Yellow.png"/>

or

<h:graphicImage library="images" name="Circle_Yellow.png" />

and include your css like below

<h:outputStylesheet library="css" name="style.css" />
Swarne27
  • 5,521
  • 7
  • 26
  • 41
  • The last two are not good: https://stackoverflow.com/questions/11988415/what-is-the-jsf-resource-library-for-and-how-should-it-be-used – Kukeltje Jun 29 '18 at 20:36