JSF - h:outputFormat

Advertisements


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

JSF Tag

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

Rendered Output

parameter 1 : Item 1, parameter 2 : Item 2 

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
6converter
Converter class name
7style
Inline style information
8title
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.

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:outputFormat example</h2>
   <hr />
   <h:form>
      <h3>Text</h3>
      <h:outputFormat value="parameter 1 : {0}, parameter 2 : {1}" >
         <f:param value="Item 1" />
         <f:param value="Item 2" />
      </h:outputFormat>	
   </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:outputFormat

Advertisements
Advertisements