Home » Enterprise Java » jsf » GraphicImage Example with JSF 2.0

About Thodoris Bais

Thodoris Bais
Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics & Telecommunications Engineering and is interested in continuous development.

GraphicImage Example with JSF 2.0

Hi there, pretty short time since my last example! This one is gonna be too short, ’cause you ‘re now enough experienced to get the best out of it.

Assuming that we ‘re building an awesome web application and we want to include an image or more in it, here comes the question: how could we get this done?

Want to be a JSF Ninja?

Subscribe to our newsletter and download the JSF 2.0 Programming Cookbook right now!

In order to get you prepared for your JSF development needs, we have compiled numerous recipes to help you kick-start your projects. Besides reading them online you may download the eBook in PDF format!


In JSF, we can use the <h:graphicImage /> tag to render an HTML img element. The approved way of including images in our application, is placing them under the webapp and especially in a structure like below:


1. JSF 1.x graphicImage

According to JSF 1.x, we could hardcode the relative path directly as a value attribute:

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

, which generates the following HTML output:

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

2. JSF 2.x graphicImage

According to JSF 2.x, we can render an image like this:

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

So, that was it for today!
This was an example of GraphicImage in JSF 2.0.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....



Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.