Access ResourceBundle keys which contain dots ?
Asked Answered
X

1

5

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?

Xenophobe answered 2/8, 2010 at 18:10 Comment(0)
R
9

You indeed need to use the brace notation, when the 'key' contains characters that have a meaning in EL, 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']}");
Rupiah answered 3/8, 2010 at 12:31 Comment(1)
So obvious... why didn't i test that? Thanks!Xenophobe

© 2022 - 2024 — McMap. All rights reserved.