<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<locale-config>
<default-locale>ja</default-locale>
<supported-locale>en</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.example.jsfexam.messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
hello=こんにちは facelet
message.param=<font color="blue">{0}</font> & <font color="orange">{1}</font>
hello=Hello facelet
message.param=<font color="blue">{0}</font> & <font color="orange">{1}</font>
<?xml version='1.0' encoding='UTF-8' ?>
<!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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:outputText value="#{msg.hello}" />
<br />
<h:outputFormat value="#{msg['message.param']}" escape="false">
<f:param value="JSF2.1" />
<f:param value="PrimeFace" />
</h:outputFormat>
<br />
<h:link outcome="welcomePrimefaces" value="Primefacesようこそページ" />
</h:body>
</html>
package com.example.jsfexam.web;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class MsgController {
@ManagedProperty("#{msg}")
private ResourceBundle bundle;
public void setBundle(ResourceBundle bundle) {
this.bundle = bundle;
}
private String helloMsg;
public String getHelloMsg() {
return helloMsg;
}
public String doMsgRead() {
helloMsg = bundle.getString("hello");
return "msgResult.xhtml";
}
}
<?xml version='1.0' encoding='UTF-8' ?>
<!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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Hello Result</title>
</h:head>
<h:body>
<h:outputText value="#{msgController.helloMsg}" />
</h:body>
</html>
FacesContext facesContext = FacesContext.getCurrentInstance();
String messageBundleName = facesContext.getApplication().getMessageBundle();
Locale locale = facesContext.getViewRoot().getLocale();
ResourceBundle bundle = ResourceBundle.getBundle(messageBundleName, locale);