tags:

views:

128

answers:

1

My JSF2 application is fully internationalized, using a ResourceBundle.

Now i have a lot of Javascript-code, which does some alerts and stuff. There i would like to access my ResourceBundle. I could successfully access simple ResourceBundle keys like this:

alert("#{bundle.message_email_sent}");

Unfortunately, my convention for keys in my bundle is to use dots . as seperators for my keys, for example message.email.sent=E-Mails sent.. But when i do

alert("#{bundle.message.email.sent}");

JSF tries to access "email" like a function on the string returned by bundle.message. How can i tell the EL-resolver to use the whole "message.email.sent" as the key?

I also tried stuff like

alert("#{bundle[\'message.email.sent\']}");

Which also results in errors. Any suggestions?

+3  A: 

You indeed need to use the brace notation, but you don't need to escape the singlequotes, regardless of whatever JS syntax highlighter is telling you otherwise. EL runs when Java/JSF runs, not when JS runs.

alert("#{bundle['message.email.sent']}");
BalusC
So obvious... why didn't i test that? Thanks!
ifischer
You're welcome.
BalusC