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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brandy3619
    New Member
    • Jun 2010
    • 3

    #1

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

    Please find below my Java script method in which i call a java method to fetch a locale specific error message
    Code:
    alert(<%=Msgs.getMessages("MessageResources", "errors.textNotLatin");
    I can get the locale through this in my script
    Code:
    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
    Code:
    alert(<%=Msgs.getMessages("MessageResources_de", "errors.textNotLatin");
    or
    Code:
    alert(<%=Msgs.getMessages("MessageResources", "errors.textNotLatin", <%=locale%>);
    I am unable to send the locale variable as a third parameter or append it to the MessageResource s string directly. Could someone please help?
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    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

    Comment

    • brandy3619
      New Member
      • Jun 2010
      • 3

      #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.

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        Try like this
        Code:
        <%
        String str = '"MessageResources","errors.textNotLatin","'+
        %>
        document.write(locale);
        <%+"';%>
        alert(<%=Msgs.getMessages(str)%>);
        Thanks and Regards
        Ramanan Kalirajan

        Comment

        • brandy3619
          New Member
          • Jun 2010
          • 3

          #5
          I still get a compilation error. Its the single quotes.
          Will the java variable str be recognized by the alert which is JS?

          Comment

          • RamananKalirajan
            Contributor
            • Mar 2008
            • 608

            #6
            then use escape sequencing character for double quotes " \" "

            Thanks and Regards
            Ramanan Kalirajan

            Comment

            Working...