Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JSF OutputFormat Example

7 total views, 7 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

greeting=Hello {0}, Welcome to {1}!

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: 


This is how the JSF page looks like in the browser

Download the JSF Project:

  JSF_OutputFormat_Example


This post first appeared on Oracle ADF, BPM, BI And Primavera P6 Tutorials, please read the originial post: here

Share the post

JSF OutputFormat Example

×

Subscribe to Oracle Adf, Bpm, Bi And Primavera P6 Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription

×