Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:40:21+00:00 2026-06-01T17:40:21+00:00

I have helloJava.HTML in my GWT project , within that html file , i

  • 0

I have helloJava.HTML in my GWT project , within that html file , i have this javascript code

                        <script type="text/javascript">
function testJavaScript(var input){
    var var1inJS = "Default value";

    alert("Value of Var1 = " + var1inJS);
    var1inJS = input;
    alert("Value of Var1 = " + var1inJS);

    var var2inJS = "Waht is the value of Var2";

    alert("Value of Var2 = " + var2inJS);

}

now i want to call this method from my onmoduleLoad class(i.e from my java class).

is it possible ?

hellojava.html file

                            <!doctype html>
<!-- The DOCTYPE declaration above will set the     -->
<!-- browser's rendering engine into                -->
<!-- "Standards Mode". Replacing this declaration   -->
<!-- with a "Quirks Mode" doctype is not supported. -->

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <!--                                                               -->
    <!-- Consider inlining CSS to reduce the number of requested files -->
    <!--                                                               -->
    <link type="text/css" rel="stylesheet" href="HelloJSNI.css">

    <!--                                           -->
    <!-- Any title is fine                         -->
    <!--                                           -->
    <title>Web Application Starter Project</title>

    <!--                                           -->
    <!-- This script loads your compiled module.   -->
    <!-- If you add any GWT meta tags, they must   -->
    <!-- be added before this line.                -->
    <!--                                           -->
    <script type="text/javascript" language="javascript" src="hellojsni/hellojsni.nocache.js"></script>

    <script type="text/javascript">
    function testJavascript(var input){
        window.jsniAlert();
        var var1inJS = "Default value";

        alert("Value of Var1 = " + var1inJS);
        var1inJS = input;
        alert("Value of Var1 = " + var1inJS);

        var var2inJS = "Waht is the value of Var2";

        alert("Value of Var2 = " + var2inJS);

    }

    function callJava(){

    }
    </script>
  </head>

  <!--                                           -->
  <!-- The body can have arbitrary html, or      -->
  <!-- you can leave the body empty if you want  -->
  <!-- to create a completely dynamic UI.        -->
  <!--                                           -->
  <body>

    <!-- OPTIONAL: include this if you want history support -->
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

    <!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
    <noscript>
      <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
        Your web browser must have JavaScript enabled
        in order for this application to display correctly.
      </div>
    </noscript>

    <h1>JSNI EXAMPLE</h1>

    <table align="center">
      <tr>
        <td colspan="2" style="font-weight:bold;"></td>        
      </tr>
      <tr>
        <td id="nameFieldContainer"></td>
        <td id="sendButtonContainer"></td>
      </tr>
      <tr>
        <td colspan="2" style="color:red;" id="errorLabelContainer"></td>
      </tr>
    </table>
  </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:40:22+00:00Added an answer on June 1, 2026 at 5:40 pm

    The function syntax from Travis is correct, the problem is the name of the calling function and JS script is not right.

    Here are the corrections

    1. Error in the function declaration, you should not use var for
      the argument.

    2. Remove the first row window.jsniAlert();

    3. Correct the declaration of the second function function
      callJava(){
      to function callJava(){

    Here is the code (lets call the function in JS testJSnative):

    <script type="text/javascript">
    function testJSnative(input){
        //window.jsniAlert();
        var var1inJS = "Default value";
    
        alert("Value of Var1 = " + var1inJS);
        var1inJS = input;
        alert("Value of Var1 = " + var1inJS);
    
        var var2inJS = "What is the value of Var2";
    
        alert("Value of Var2 = " + var2inJS);
    
    }
    
    function callJava(){
    
    }
    </script>
    

    Example of class implementing EntryPoint:

      public void onModuleLoad() {
    
        Button jsniButton = new Button("call JS");
        jsniButton.addClickHandler(new ClickHandler() {
    
          @Override
          public void onClick(ClickEvent event) {
    
            callJavascript();
          }
        });
        RootPanel.get().add(jsniButton);
      } 
    
      public native void callJavascript() /*-{
        $wnd.testJSnative("hello");
      }-*/;
    

    I hope this will be helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work this out. In my project, i have a file called
Have written all the code in a silverlight class library (dll) and linked this
Have some dates in my local Oracle 11g database that are in this format:
have the following text file: <div> <asp:HyperLinkField HeaderText=Hello World of Regular Expression /> </div>
Have an app that can use tts to read text messages. It can also
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
have a look at the code from an xml file where i am using
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you managed to get Aptana Studio debugging to work? I tried following this,
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.