Locked History Actions

Diff for "GWT/TIPS"

Differences between revisions 3 and 4
Deletions are marked like this. Additions are marked like this.
Line 44: Line 44:

== DialogBoxのoffsetWidthが必ず400になっている ==

自動生成されるcssになぜか
{{{
/** Most GWT widgets already have a style name defined */
.gwt-DialogBox {
  width: 400px;
}
}}}
という定義があるため。

TIPS

クライアント内のリソースをユーザにダウンロードさせる

ユーザに何かをダウンロードさせるには、URLを示してサーバからダウンロードさせるのが普通だが、 ここでは、クライアント内にあるリソースを(当然のことながらサーバを介さずに)ユーザにダウンロードさせてみる。 ここでは簡単なテキストをダウンロードさせる。

        String downloadText = "なんでもいい";
        String windowName = "test.txt";
        
        byte[]bytes;
        try {
          // なぜかutf-8ではだめ。これはバグとしてあがっている
          bytes = downloadText.getBytes("UTF-8");
        } catch (Exception ex) {
          ex.printStackTrace();
          return;
        }
        String base64 = new String(Base64Coder.encode(bytes));
        String dataUri = "data:application/octet-stream;base64," + base64;
        Window.open(dataUri, windowName, "");

Base64Coderhttp://www.source-code.biz/base64coder/java/を使う。ただし、この中の

  private static final String systemLineSeparator = System
      .getProperty("line.separator");

はGWTクライアント側で動作しないので、

  private static final String systemLineSeparator = "\n";

とでもしておく。 ちなみに、com.google.gwt.user.server.Base64Utilsというものがあるが、クライアントサイドで動作させる方法が不明。

以上でとりあえずダウンロードはできるが、ファイル名を指定する方法は不明。

マウスカーソル形状の変更

DialogBoxのoffsetWidthが必ず400になっている

自動生成されるcssになぜか

/** Most GWT widgets already have a style name defined */
.gwt-DialogBox {
  width: 400px;
}

という定義があるため。