JSF Message Resources

Reading Time: < 1 minute

in src/main/resource create file called “MessageResources.properties” in which we will define our messages here

footerText=This text is defined in the MessageResource.properties file

Then add the below lines into your “faces-config.xml” file to identify the messages bundle into the application;

	<application>
		<resource-bundle>
			<base-name>MessageResources</base-name>
			<var>messages</var>
		</resource-bundle>
	</application>

then in any of your .xhtml file you are good to implement the resource you define in your properties file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>${project.artifactId} Application</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<h:outputStylesheet name="css/screen.css" />
</h:head>
<h:body>
	<h:panelGroup id="page" layout="block">
		<h:panelGroup id="header" layout="block">
			<h1><a href="home.jsf">fastapp</a></h1>
		</h:panelGroup>
		<h:panelGroup id="container" layout="block">
			<h:panelGroup id="sidebar" layout="block">
				<h1>Sidebar</h1> Content for the sidebar goes here
			</h:panelGroup>
			<h:panelGroup id="content" layout="block">
				<ui:insert name="content">Main Content</ui:insert>
			</h:panelGroup>
		</h:panelGroup>
		<h:panelGroup id="footer" layout="block">#{messages.footerText}
		</h:panelGroup>
	</h:panelGroup>

</h:body>
</html>