1

gwt を使い始めたばかりですが、コードで作成するボタンを指定しているにもかかわらず、アプリにボタンが表示されない理由がわかりません。

私のエントリーポイントクラスは

package com.france.webapp.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class MyEntryPoint implements EntryPoint {

public MyEntryPoint(){
}

    @Override
    public void onModuleLoad() {
    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");
      }
    });

    RootPanel.get().add(label);
    RootPanel.get().add(button);
  }
}

私は最新バージョンのjdkとeclipse junoを搭載したWindowsを使用しています。アプリが実行され、htmlページが表示されますが、ボタンは表示されません。gwt 開発プラグインを使用して、最新バージョンの chrome と firefox 20 でテストしました。

プロジェクトをコンパイルする必要がありますか?それとも、[実行] -> [Web アプリケーション] オプションでボタンを表示するのに十分でしょうか? 私の gwt.xml は問題ないようで、http: //www.vogella.com/articles/GWT/article.html のチュートリアルに従っています。

これは私の MyModule.gwt.xml です

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module>
    <inherits name="com.google.gwt.user.User" />
    <source path="client" />
    <entry-point class="com.france.webapp.client.MyEntryPoint"></entry-point>
</module>

私のhtml.htmlファイル

<!doctype html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>html</title>
    <script type="text/javascript" language="javascript" src=".nocache.js"></script>
  </head>

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

  </body>
</html>

私はEclipseコンソールを見てきましたが、これはそれが読むものです

[WARN] 404 - GET /.nocache.js (127.0.0.1) 1397 bytes
   Request headers
      Host: 127.0.0.1:8888
      Connection: keep-alive
      Accept: */*
      User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: en-US,en;q=0.8
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
      Referer: http://127.0.0.1:8888/html.html?gwt.codesvr=127.0.0.1:9997
4

1 に答える 1

1

html ファイルに問題がある可能性があります。コードを正常に実行しました。プロジェクトの war フォルダーの下にある html ファイルの内容としてこれを試してください。

<!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="MyEntryPoint.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="myentrypoint/myentrypoint.nocache.js"></script>
  </head>
  <body>
  </body>
</html>

そして、これが com.france.webapp パッケージの下のプロジェクト xxx.gwt.xml にあることを確認してください。

<entry-point class='com.france.webapp.client.MyEntryPoint'/>

Eclipse/jetty を介してアプリを実行すると、ウィジェットがロードされるまでに数秒、場合によっては 10 秒以上かかります。

于 2013-05-10T17:06:00.467 に答える