JSF - h:outputFormat


The h:outputFormat tag renders an HTML text but can accept parameterised inputs.


<h:outputFormat value = "parameter 1 : {0}, parameter 2 : {1}" > 
   <f:param value = "Item 1" /> 
   <f:param value = "Item 2" /> 

Rendered Output

parameter 1 : Item 1, parameter 2 : Item 2 

Tag Attributes

S.No Attribute & Description
1 id

Identifier for a component

2 binding

Reference to the component that can be used in a backing bean

3 rendered

A boolean; false suppresses rendering

4 styleClass

Cascading stylesheet (CSS) class name

5 value

A component’s value, typically a value binding

6 converter

Converter class name

7 style

Inline style information

8 title

A title, used for accessibility, that describes an element. Visual browsers typically create tooltips for the title’s value

Example Application

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

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


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns = "http://www.w3.org/1999/xhtml">
      <title>JSF Tutorial!</title>
      <h2>h:outputFormat example</h2>
      <hr />
         <h:outputFormat value = "parameter 1 : {0}, parameter 2 : {1}" >
            <f:param value = "Item 1" />
            <f:param value = "Item 2" />

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 the following result.

JSF h:outputFormat