162 total views, 5 views today

JSF OutputFormat Example

 

The JSF OutputFormat allow us to display text dynamically using parameters. The Pattern for the format of the text is based on java.text.MessageFormat. Let’s look at the following example,

 

Hello Govind, Welcome to JSF Tutorials!

 

Here I want to generate the texts ‘Govind’ and ‘JSF Tutorial’ dynamically based on user logs in and what tutorials he is currently reading, So instead of hardcode the above text I will phrase it like below and pass the values for {0} and {1} at runtime. The JSF outputFormat is going to help on this.  

 

Hello {0}, Welcome to {1}!

 

The below example explains how <h:OutputFormat> works with an example:

 

JSF h:outputFormat Example

 

Below is the ResourceBundle properties file contains a name:value pair. We are going to pass the {0} and {1} at runtime

 

 

 

Below is the JSF page contains an h:outputFormat referring the above property. The variable ‘message’ is a handle to the property file mentioned in the faces-config.xml. 

Here I m passing the params at runtime. I have hardcoded the values but we can pass the values dynamically from the backing bean properties i.e GET method. For Example:  <f:param value=”#{user.name}” />

 

 


This is how the JSF page looks like in the browser

 

 

JSF_OutputFormat_Example JSF OutputFormat Example

 

 

Download the JSF Project:

 

govindan JSF OutputFormat Example
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply šŸ™‚
govindan JSF OutputFormat Example
Connect me
By | 2017-11-23T12:27:52+00:00 November 23rd, 2017|Categories: JSF|Tags: , , , |0 Comments
Like us on Facebook.
Connect!