• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Multilingual JSF

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default answer to having a multilingual page when developing an application is to develop two pages. This will usually add the complexity of managing the pages by resulting in the added effort of maintaining both pages/forms when having adding/amending a function. A simple solution to the problem is by considering the language to be as a separate function and manage it accordingly.

In-line with the function of multi-lingual, let us use the terminology of Function-Oriented application (as a sub-level of OO) where the function of presentation is isolated from the function of language and, as such, is isolated from the core function of the application. Within JSF, you can easily isolate the functionality of a multi lingual application. Let us start by a bundle two bundle files (This can be in a database if you prefer). Here I will use Arabic and English



Then Create a Managed Bean with the scope set as Session Scoped (This is to ensure you maintain the selected language)

Finally, your JSF page. Depending on the label you need to retrieve, you may use the expression language in the following form:

where dir while define the orientation of the page (left to right or right to left), next and previous will refer to the label title next and Previous respectively in the bundle bundle file based on the selected language. By implementing you code in the above manner, you open the opportunity to configure new languages as you feel free and it will require minimum maintenance from a technical perspective.

Saloon Keeper
Posts: 22986
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your contribution Mujtaba.

However, the construct:

is bad practice. You should almost never code function calls in your View Definition, whether it's mono-lingual or multi-lingual. Even worse is if you put parameters in such calls. JSF works primarily on server-side data.

Code an action method reference, instead.

Likewise for properties:

Should be

Where the "label" property is a Map object. Or, when using multiple languages, a façade for whichever Bundle map is presently used for the selected language.
Mujtaba Alsaif
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim

I was unaware. However, I was attempting to provide a generic template to develop multi lingual apps.
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic