JSF - h:graphicImage

Advertisements


The h:graphicImage tag renders an HTML element of the type "img".

JSF Tag

<h:graphicImage 
   value="http://www.tutorialspoint.com/images/jsf-mini-logo.png"/>

Rendered Output

<img src="http://www.tutorialspoint.com/images/jsf-mini-logo.png" />

Tag Attributes

S.N.Attribute & Description
1id
Identifier for a component
2binding
Reference to the component that can be used in a backing bean
3rendered
A boolean; false suppresses rendering
4styleClass
Cascading stylesheet (CSS) class name
5value
A component’s value, typically a value binding
6alt
Alternative text for nontextual elements such as images or applets
7dir
Direction for text. Valid values are ltr (left to right) and rtl (right to left).
8lang
Base language of an element’s attributes and text
9style
Inline style information
10tabindex
Numerical value specifying a tab index
11target
The name of a frame in which a document is opened
12title
A title, used for accessibility, that describes an element. Visual browsers typically create tooltips for the title’s value
13usemap
Usemap of an element
14url
Url of the image
15width
Width of an element
16onblur
Element loses focus
17onchange
Element’s value changes
18onclick
Mouse button is clicked over the element
19ondblclick
Mouse button is double-clicked over the element
20onfocus
Element receives focus
21onkeydown
Key is pressed
22onkeypress
Key is pressed and subsequently released
23onkeyup
Key is released
24onmousedown
Mouse button is pressed over the element
25onmousemove
Mouse moves over the element
26onmouseout
Mouse leaves the element’s area
27onmouseover
Mouse moves onto an element
28onmouseup
Mouse button is released

Example Application

Let us create a test JSF application to test the above tag.

StepDescription
1Create a project with a name helloworld under a package com.tutorialspoint.test as explained in the JSF - First Application chapter.
2Modify home.xhtml as explained below. Keep rest of the files unchanged.
3Compile and run the application to make sure business logic is working as per the requirements.
4Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver.
5Launch your web application using appropriate URL as explained below in the last step.

home.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>JSF Tutorial!</title>
</head>
<body>
   <h2>h:graphicImage example</h2>
   <hr />
   <h:form>      
      <h3>Image</h3>
      <h:graphicImage value="/images/jsf-mini-logo.png"/>
   </h:form>
</body>
</html>

Once you are ready with all the changes done, let us compile and run the application as we did in JSF - First Application chapter. If everything is fine with your application, this will produce following result:

JSF h:graphicImage

Advertisements
Advertisements