In JSF, you can use <h:graphicImage /> tag to render a HTML “img” element. For example, an image named “sofa.png” in a resources folder, see figure below :


1. JSF 1.x graphicImage

In JSF 1.x you can hard-coded above image URL directly in the “value” attribute :


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

HTML output…

<img src="resources/images/sofa.png;" alt="" />

2. JSF 2.x graphicImage

In JSF 2.0, you can render above image via “resource library” concept :


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

HTML output…

<img src="/JavaServerFaces/faces/javax.faces.resource/sofa.png?ln=images" alt="" />
For more detail, please read this JSF 2.0 resource library example.

Download Source Code

Download It – (14KB)


  1. JSF <h:graphicImage /> JavaDoc
Tags :
Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Related Posts

Popular Posts