Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internationalization in JSF

 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

Please could someone give me some advice on internationalization best practice for JSF. I know what I am trying to achieve but not the best method. I would appreciate any guidance.

Requirements
============
I want a ResourceBundle accessible to my JSF pages, backing beans and model objects loaded from a properties file.
I dont want to load the ResourceBundle for every page or object use, I would like it stored in session scope.
The localised resource bundle has to be of the type LC_CC_VC where LC=language, CC=country and VC=variant.
I would like to be able to access messages in JSF pages using expression language.

Can anyone advise how I can achieve the above?

Where should I set the Locale in the UIViewRoot?
Do I need to set the supported locales in the XML config file?
Should I ignore the JSF features and just create my own ResourceBundle and stick it in Session scope?
How can I access messages from a resource bundle without having a specific getter?

What would you do?

Thanks for your advice in advance - there are too many options for me to pick the best way to do this.

So far I have tried this route
==============================
Extract locale from DB after login
Create ResourceBundle in login method of backing bean
Store Resourcebundle in session scope

This is OK but it means I cannot use EL to access my messages so I am looking for another solution.

Cheers
 
Chris Gage
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF should do it all for you provided you tell it which languages you want to enable in the faces-config.xml file.

Fort example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="../theme/Master.css" />
<title>Yada Yada Yada</title>
</head>
<f:view>
<f:loadBundle var="MyMain" basename="MyMain" />
<body>
<h utputText value="#{MyMain.my_message_key}" />
</body>
</f:view>
</html>

and in your faces-config.xml, something like:

<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>fr</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>nl</supported-locale>
...
</locale-config>
</application>
 
Chris Gage
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ignore the silly face which the website inserted without asking me. It replaced a colon followed by a letter o with this silly symbol.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a view is not associated with a locale explicity, JSF uses "Accept-Language" header in request data from browser to find out the locale to be picked. It compares the header's values with the ones configured in faces-config.xml and if no match is found default locale is selected.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chris Gage:
Please ignore the silly face which the website inserted without asking me. It replaced a colon followed by a letter o with this silly symbol.


Alternatively, while replying you may check Disable smilies in this post. option at the bottom of the screen
 
Ronald Johnson
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am coding a "switch language" into an app,
and my idea is that i have a bean that stores the language setting.
as default, the Accept-language should be used,
i.e. in the bean, i would either returned the user defined lanuage or the value of Accept-language.

how can i read out the value of Accept-language from my java code?
 
Y Jadhav
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Gage wrote:Please ignore the silly face which the website inserted without asking me. It replaced a colon followed by a letter o with this silly symbol.


CHECK "Disable Smilies ...." option while sending reply...
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kind of you, but in the future please don't resurrect old and dead topics. Just leave them for what they are and respond to active topics in the listing only.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic