By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

How to send a JS variable within a scriptlet tag to call a Java method?

P: 3
Please find below my Java script method in which i call a java method to fetch a locale specific error message
Expand|Select|Wrap|Line Numbers
  1. alert(<%=Msgs.getMessages("MessageResources", "errors.textNotLatin");
I can get the locale through this in my script
Expand|Select|Wrap|Line Numbers
  1. var locale = document.UserForm.preferredLanguage.value;
I need to send this 'locale' value along with the alert message
For eg it should read as below for locale germany
Expand|Select|Wrap|Line Numbers
  1. alert(<%=Msgs.getMessages("MessageResources_de", "errors.textNotLatin"); 
or
Expand|Select|Wrap|Line Numbers
  1. alert(<%=Msgs.getMessages("MessageResources", "errors.textNotLatin", <%=locale%>);
I am unable to send the locale variable as a third parameter or append it to the MessageResources string directly. Could someone please help?
Jun 14 '10 #1
Share this Question
Share on Google+
5 Replies


RamananKalirajan
100+
P: 607
If you are working in a JSP, why cant you set those variables in request or session to get that value in Java function.

Thanks and Regards
Ramanan Kalirajan
Jun 14 '10 #2

P: 3
I would not be submitting the form. This is for validating the input and dynamically displaying the error message in a locale specific language.
Jun 14 '10 #3

RamananKalirajan
100+
P: 607
Try like this
Expand|Select|Wrap|Line Numbers
  1. <%
  2. String str = '"MessageResources","errors.textNotLatin","'+
  3. %>
  4. document.write(locale);
  5. <%+"';%>
  6. alert(<%=Msgs.getMessages(str)%>);
Thanks and Regards
Ramanan Kalirajan
Jun 15 '10 #4

P: 3
I still get a compilation error. Its the single quotes.
Will the java variable str be recognized by the alert which is JS?
Jun 15 '10 #5

RamananKalirajan
100+
P: 607
then use escape sequencing character for double quotes " \" "

Thanks and Regards
Ramanan Kalirajan
Jun 15 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.