1

Is there a best practice for translating dynamic values comming from the backend (hibernate/mysql) in the JSF frontend. Just image you would like to show them in an oneselectmenu.

My question is only scoping all values comming from the database...stuff like gender, salutation and so on. All these stuff is stored in the database. All static values like labels for input fields and so on are already translated by using language message property files.

What would be your approach here?

Ugur Teker
  • 169
  • 2
  • 14

1 Answers1

1

Let's say you have saved gender values in your database and you want to internationalize it in p:selectOneMenu.

First create your key messages, for example:

choose = Choose
gender = Gender
database.gender.MALE = Male
database.gender.FEMALE = Female

With keys like that your stored values in database (and returned by dao) have to look like MALE and FEMALE.

Then you can use this code for i18n

<p:outputLabel value="#{msg.gender}"/>
<p:selectOneMenu value="#{bean.chosenGender}">
    <f:selectItem itemLabel="#{msg.choose}" itemValue="" />
    <f:selectItems var="gender" value="#{bean.genderList}" 
                   itemLabel="#{msg['database.gender.' += gender]}" />
</p:selectOneMenu>
Geinmachi
  • 1,251
  • 1
  • 8
  • 20
  • That sounds like a reasonale approach. Only downgrade here is that this is not really dynamic since i need to redeploy the app (or the message file) everytime i want to add a new values to the database which needs to be translated. But i think this is a small downgrade anyway. – Ugur Teker Nov 15 '15 at 16:16
  • Then put everything including translations in the database and make a database based resource/message bundle – Kukeltje Nov 15 '15 at 16:24
  • oh yes. Thats it! Thanks a lot! – Ugur Teker Nov 15 '15 at 17:08