aspose file tools*
The moose likes JSF and the fly likes JSF 2 - Internationalization - Message Resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF 2 - Internationalization - Message Resources " Watch "JSF 2 - Internationalization - Message Resources " New topic
Author

JSF 2 - Internationalization - Message Resources

Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

Hi

Im developing on JSF2 + Facelets and have several languages in my app

All works fine, but eclipse (Helios) shows me an annoying red X in the header.xhtml file

this is how it starts...



The RED X appears on the line of the <f:loadBundle

It says: "Resource bundle dr.messageresource.MessageResources cannot be found on classpath"

Again.. all works well , I just want to get rid of the annoying informative RED X

In my java resource i have package named "dr.messageresource" and got files like this one MessageResources_en.properties

and faces config got the needed defentions:
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

Define a Class variable that references your folder location where you have the properties file and add this new classpath in the 'CLASSPATH' setting of your eclipse projects' run configuration.

Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

|Any chance that you can guide me in this?

I tried the following without any luck:

In Java Build path: Source tab : add folder (added the dr.messageresource package) : nothing helpful came out of this

In Java Build path: Libraries tab : add class folder (added the dr.messageresource package) : nothing helpful came out of this



How do i do this : "Define a Class variable that references your folder location" ?
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

Okie! Here you go!

Go to your project properties-

Navigate to Resources - Linked Resources
and Create a new variable in Path Variables 'dr.messageresource.MessageResources'. Have this point to your message bundle.

Let me know if that works!
Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

Not working :/

did the follwoing

http://img710.imageshack.us/img710/844/langs.png

in xhtml file did this: <f:loadBundle basename="langs" var="msg"/>

got this exception:

javax.faces.view.facelets.TagAttributeException: /WEB-INF/templates/header.xhtml @9,45 <f:loadBundle basename="langs"> Can't find bundle for base name langs, locale en
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

Sorry! I was kinda thinking on other lines while replying earlier ---

Just change MessageResources to MessageResources_en both in your prev implementation code.
both in faces-config as well as your jsp.

That should solve it.
Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

<f:loadBundle basename="dr.messageresource.MessageResources_en" var="msg"/>



getting this exception :

javax.faces.view.facelets.TagAttributeException: /WEB-INF/templates/header.xhtml @9,78 <f:loadBundle basename="dr.messageresource.MessageResources_en"> Can't find bundle for base name dr.messageresource.MessageResources_en, locale en

Thans ahead
Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

after some struggle i managed to get rid of the

javax.faces.view.facelets.TagAttributeException: /WEB-INF/templates/header.xhtml @9,78 <f:loadBundle basename="dr.messageresource.MessageResources_en"> Can't find bundle for base name dr.messageresource.MessageResources_en, locale en

but the problem that is that the localization stopped to work... no i got only English language and cannot switch to other languages
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

Yeah! I see where you are pointing to now. Let me set this up quickly at my end and test.
Daniel Reznick
Ranch Hand

Joined: Oct 23, 2008
Posts: 50

I got it working

i added an empty file with the name MessageResources.properties

That's it


no red X anymore

Thanks for the help dude!
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

The compiler error was your issue or was it being able to pick multiple locales. So now are you able to test it for different locales?
Sai Hegde
security forum advocate
Ranch Hand

Joined: Oct 26, 2010
Posts: 200
    
    1

Yeah, That was what it was. You need to have a default properties file with the name similar to the message bundle that you have configured.
The default file can be used as a template for your other files.
Supported locales/default locales will be configured through files appended with locale identifiers.

Cheers!!!
 
 
subject: JSF 2 - Internationalization - Message Resources