Reputation: 115
I have a an object stored in the model called "domain", which has two methods, getDescriptionEn() and getDescriptionFr().
I need the description depending on the current locale.
Here is my problem, I have the following:
var locale = "${currentLocale}"; // This returns either "En" or "Fr"
var method = "{domain.getDescription".concat(locale).concat("}"); // This is "{domain.getDescriptionEn}" or "{domain.getDescriptionFr}"
var expr = "$".concat(method); // This is going to be "${domain.getDescriptionFr}"
now I would like to evaluate this expressoin but it does not seem to work.
I have tried parsing the strings many different ways,
I also tried:
var method = "domain.getDescription".concat(locale); // This is "domain.getDescriptionEn" or "domain.getDescriptionFr"
var expr = "${".concat(method).concat("}");
Upvotes: 0
Views: 1662
Reputation: 6322
By the time your javascript gets a chance to run on the client the JSP has already been evaluated (along with any EL) and you won't be able to access model that way.
However, you can do all that you want directly in the JSP. Use ${pageContext.request.locale}
to access the locale of the client's request and pass it on to your method.
Upvotes: 2