简体   繁体   English

从Eclipse执行GWT应用程序

[英]Executing GWT application from eclipse

I am a beginner in GWT. 我是GWT的初学者。 i came up with my entry class as follows: 我想出了我的入门课程,如下所示:

public class HelloWorld implements EntryPoint {


public void onModuleLoad() {
    // TODO Auto-generated method stub
    Label label = new Label("Hello GWT !!!");
    Button button = new Button("Say something");
    button.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            Window.alert("Hello, again");
        }

    });

    try{
    RootPanel.get("hold").add(label);
    RootPanel.get("hold").add(button);
    }catch(Exception e){
        System.out.println(e.toString());
    }
}

}

and the xml file to declare the entry class as: 以及将条目类声明为的xml文件:

 <?xml version="1.0" encoding="UTF-8"?>
<module rename-to='testgwt'>
  <inherits name='com.google.gwt.user.User'/>
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <!-- Specify the app entry point class -->
  <entry-point class="com.jade.testgwt.client.HelloWorld"/>
</module>

the html file is as follows: html文件如下:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link type="text/css" rel="stylesheet" href="TestGWT.css">
    <title>My First GWT applicaton</title>
    <script type="text/javascript" language="javascript" src="testgwt/test_gwt.nocache.js"></script>
  </head>

  <body>
    <h1>My First GWT applicaton</h1>
    <div id="hold"></div>

  </body>
</html>

so i was expecting to see the label and button control on the web page when i run by right clicking on the project and choosing Run as Web application. 因此,我希望通过右键单击项目并选择“以Web应用程序运行”方式运行时,在网页上看到标签和按钮控件。 I only got to see the h1's tags text. 我只看到了h1的标签文本。 don't know why the label and button is not showing? 不知道为什么标签和按钮没有显示?

Instead of RootPanel.get("hold").add(...) , try this: 代替RootPanel.get("hold").add(...) ,请尝试以下操作:

RootLayoutPanel.get().add(label);
RootLayoutPanel.get().add(button);

What is the fully qualified name of your GWT module? 您的GWT模块的标准名称是什么? I don't think that test_gwt.nocache.js is correct if the module name is testgwt . 如果模块名称为testgwt ,我认为test_gwt.nocache.js是正确的。 Try removing the underscore. 尝试删除下划线。 In any case, you could install Firebug in Firefox to monitor the network activity and see if the request to fetch the JS is failing. 无论如何,您都可以在Firefox中安装Firebug来监视网络活动,并查看获取JS的请求是否失败。

Edit: If you create a "New Web Application" project in Eclipse, a working sample application is generated to which you could compare your code. 编辑:如果您在Eclipse中创建“新Web应用程序”项目,则会生成一个工作示例应用程序,您可以将其与您的代码进行比较。

You need to take panel. 您需要参加小组讨论。 And in that panel add your label and button. 然后在该面板中添加标签和按钮。

That panel will be added in RootPanel.get("hold").add(...). 该面板将添加到RootPanel.get(“ hold”)。add(...)中。

Add this line to you HTML page below the division with id "hold" 将此行添加到ID为“ hold”的部门下方的HTML页面中

<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position: absolute; width: 0; height: 0; border: 0"></iframe>

You missed out this line. 您错过了这一行。

Also Edit the script tag in the HTML Page as, 另外,将HTML页面中的脚本标签编辑为

Make sure a testgwt.nocache.js exist under your testgwt folder 确保您的testgwt文件夹下存在一个testgwt.nocache.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM