• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us

How to use Resource Bundle in JSF?

April 12, 2008 //  by Krishna Srinivasan

  • Topic : Java Server Faces (JSF)
  • Environment : J2EE 5.0, MyFaces 1.1.5

Resource Bundle in JSF

also read:

  • Introduction to JSF
  • JSF Interview Questions
  • Request Processing Lifecycle phases in JSF

This section explain how to use message resources in Java Server Faces (JSF). Resource Bundles are very important when comes to internationalization.JSF framework provides simple way to configure and use th message resources in your application. Follow the steps to configure resource-bundle:

  • Step :1 Create a properties file. In our example we have created ApplicationResources.properties
  • Step :2 Add message-bundle element in the faces-config.xml. for more details see the complete program in the example section.
  • Step :3 Load the bundle using f:loadBundle tag in jsp file.
  • Step :4 Use the “msg” varible (which is defined while loading the message bundle) in the tags to get message resources.

applicationResources.jsp

<!--
   Source : www.javabeat.net
-->


<f:loadBundle basename="net.javabeat.myfaces.resource.ApplicationResources" var="msg"/>
<html>
    <body>
        <f:view>
            <h:form id="resources">
                <h:outputFormat value="#{msg.testMessage1}">
                    <f:param value="Apple"/>
                    <f:param value="Google"/>
                </h:outputFormat>
                <h:outputLabel value="#{msg.testMessage2}"/>
            </h:form>
        </f:view>
    </body>
</html>

faces-config.xml


    <application>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
        <message-bundle>
            net.javabeat.myfaces.resource.ApplicationResources
        </message-bundle>
    </application>

ApplicationResources.properties


# Sample ResourceBundle properties file
testMessage1={0} and {1} is most innovative companies in IT
testMessage2=Google - The internet God

Category: JavaTag: JSF Tags

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « How to set selected tab in rich:tabPanel tag?
Next Post: Entity Beans in EJB(CMP) »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Initialize an Array in Java

Introduction to Java Server Faces (JSF)

Introduction to Java 6.0 New Features, Part–1

Java 6.0 Features Part – 2 : Pluggable Annotation Processing API

Introduction to Java Server Faces(JSF) HTML Tags

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact