Internationalization with JSF

Hi Everyone,

Here is what happens in my App:

When index.jsp is hit, I determine wether its an authorized/unauthorized login. Based on that user is either forwarded to search/error jsp's. Now I have to add Multi Lingual support to the app. Basically the aplication will be invoked from a portal like app so the URL will look like this :

http://xyz.corp.xyz.com:7780/appsell_uat_xyz/faces/index.jsp?&languageCd=ENG&userId=MPENIKELAPATI

Now I am supposed the pick up the language from the above URL and set the locale accordingly.

I want to set the locale while I am on index.jsp only determing access authority. The way I tried to do this is (I have a bean asociated with index.jsp, this code goes in that bean) :

if(languageCd == "JA"){

context.getViewRoot().setLocale(Locale.JAPANESE);

}

Faces config:

<navigation-rule>

<from-view-id>/index.jsp</from-view-id>

<navigation-case>

<from-outcome>success</from-outcome>

<to-view-id>/search.jsp</to-view-id>

<redirect/>

</navigation-case>

</navigation-rule>

<navigation-rule>

<from-view-id>/index.jsp</from-view-id>

<navigation-case>

<from-outcome>error</from-outcome>

<to-view-id>/error.jsp</to-view-id>

<redirect/>

</navigation-case>

</navigation-rule>

<application>

<locale-config>

<default-locale>en</default-locale>

<supported-locale>ja</supported-locale>

</locale-config>

</application>

Problem here is if I try to set the local in index.jsp only, viewRoot is not search.jsp yet. So the labels are of default locale. I also tried to set the local in the constructor of search.jsp. This works, but is a very unclean solution as on all the hits code will be executed. One additional problem with this approach is when control is redirecting from index to search jsp, I see all the labels in English for a very small time then the labeles change to Japanease.

I think I dont understand Localization approach of JSF at all. I read local will be picked up from browser setting, but I dont know how will that behave.

I will appreciate a great deal if someone can clear my concepts here!

Thanks in advance!

[2368 byte] By [tizia] at [2007-11-27 10:58:53]
# 1

Yes, by default JSF will use the locale from the client, determined from the Accept-Language header. If this is not suitable to your application, I recommend using a servlet filter to set the locale according to your scheme by wrapping the request object and overriding ServeltRequest.getLocale(). You could determine the locale once from URL and then store it in the session or a cookie, whichever suits your needs.

RaymondDeCampoa at 2007-7-29 12:19:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for replying!

I am sorry, but I dont understand how should I go with the approach you suggested.

Can you please be elaborate on this?

tizia at 2007-7-29 12:19:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I resolved the problem.

Thanks a lot for taking interest in my problem!

tizia at 2007-7-29 12:19:14 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...