从GWT应用程序导出数据的最佳方式?

时间:2011-12-08 11:50:06

标签: php gwt

我编写了一个科学的GWT应用程序,它基本上只是询问参数,执行计算然后绘制结果(不显示数字数据)。它运作得很好。

现在用户问我“导出”数据的方法(1000个双精度数字)。我该怎么做?我想:

a)最优雅的方式是打开“另存为...”对话框的“导出数据”按钮。如果我理解正确,出于安全原因,在客户端无法做到这一点。但是我无法在服务器上运行Java servlet,并且数据集太大而无法为PHP脚本提供URL。

b)将数据复制到剪贴板的按钮可能是下一个最好的选择。但似乎GWT目前没有实现这一点,并且JSNI中的跨浏览器解决方案会很复杂。如果出现故障,用户将无法访问数据。

c)用于打开PopUpPanel或显示数字数据的新窗口的按钮。最后一招。应该以允许“全选”的方式实现,只选择数据。

有什么想法?谁能想到避免c)的方法?感谢。

1 个答案:

答案 0 :(得分:0)

您可以POST将数据发送到PHP脚本。您不必在URL中传递它。您可以使用FormPanel类将数据发布到任何服务器端脚本。

JavaDoc页面上有一个例子,但它会是这样的:

FormPanel form = new FormPanel();
form.setAction("/yourPhpScript.php");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);

Hidden postData = new Hidden();
postData.setName("dataset");
postData.setValue( /* your data set */ );

form.add(postData);


form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
  public void onSubmitComplete(SubmitCompleteEvent event) {
    // When the form submission is successfully completed, this event is
    // fired. Assuming the service returned a response of type text/html,
    // we can get the result text here (see the FormPanel documentation for
    // further explanation).

    // So what you want to return from your PHP script is a link to a URL of the exported results
    Window.alert(event.getResults());
  }
});

RootPanel.get().add(form);