pour m'introduire dans l'utilisation des resource bundle avec jsf j'ai utiliser un tuto qui se compose de 3 ressources bundles:
MessageResources_de.properties
Code :
welcome=Willkommen auf der Seite
login={0} hat sich eingeloggt am {1}.
imagePath=/images/image_de.gif
MessageResources_en.properties
Code :
welcome=Welcome on this site.
login={0} have be logged in on {1}.
imagePath=/images/image_en.gif
MessageResources_en_US.properties
Code :
welcome=Welcome on this site.
login={0} have be logged in on {1}.
imagePath=/images/image_en_US.gif
et une classe:
Code :
publicclass Utils {
protectedstatic ClassLoader getCurrentClassLoader(Object defaultObject){
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader == null){
loader = defaultObject.getClass().getClassLoader();
}
return loader;
}
publicstatic String getMessageResourceString(
String bundleName,
String key,
Object params[],
Locale locale){
String text = null;
ResourceBundle bundle =
ResourceBundle.getBundle(bundleName, locale,
getCurrentClassLoader(params));
try{
text = bundle.getString(key);
}catch(MissingResourceException e){
text = "?? key " + key + " not found ??";
}
if(params != null){
MessageFormat mf = new MessageFormat(text, locale);
text = mf.format(params, new StringBuffer(), null).toString();
}
return text;
}
}
et un bean :
Code :
publicclass MyBean {
public String getWelcomeMessage(){
FacesContext context = FacesContext.getCurrentInstance();
String text = Utils.getMessageResourceString(context.getApplication()
.getMessageBundle(), "welcome", null, context.getViewRoot()
.getLocale());
return text;
}
}
et en fin la jsp:
Code :
<%@ page language="java" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JSF message resource</title>
</head>
<body>
<f:view>
<f:loadBundle basename="de.laliluna.tutorial.messageresource.MessageResources"
var="msg"/>
<h:outputText value="#{msg.welcome}" />
<br><br>
<h:outputFormat value="#{msg.login}">
<f:param value="Peter" />
<f:param value="10/03/2005" />
</h:outputFormat>
<br><br>
<h:graphicImage value="#{msg.imagePath}" />
<br><br>
<h:outputText value="#{myBean.welcomeMessage}" />
</f:view>
</body>
</html>
mon question est le suivant:
dans la jsp il ya appel de
Code :
<f:loadBundle basename="de.laliluna.tutorial.messageresource.MessageResources"
var="msg"/>
mais il n'ya pas specification du resourcebundle a utiliser;
par exemple, comment faire pour utiliser la langue anglaise et comment faire pour selectionner la langue (deutch).
et d'autre terme comment passer d'une laugue a une autre