6

在你开始击落我之前,我已经检查了答案,我已经用谷歌搜索直到我的手指流血,但我无法找到一个简单、简洁的答案。所以我再次询问所有可能有这个问题的人。

问题:如何打开一个侧面有窗体的新窗口。

上下文:我有一个列出很多项目的应用程序,我希望有人编辑一个条目,我希望打开一个新窗口,以便他们可以编辑属性然后点击保存。您可以在许多应用程序中找到标准的东西。

架构: 我有一个名为 UI 的客户端模块,它有十几个类来绘制小部件并在从菜单中选择时填充主要区域。我有一个名为 UI.html 的 html 页面,它的头部有标签。而已。

我见过的选项

  1. 调用Window.Open()但您需要定义一个 html 文件。我没有。我可以创建一个空的,但是如何向其中注入一个小部件?

  2. 使用jsni $wnd创建一个新窗口并获取对它的引用。但是我如何将表单面板注入其中?

  3. 使用弹出面板。它们看起来很糟糕——另外,如果通过 JS 打开一个窗口非常简单,我希望它会在 gwt 中。

也许我想念如何使用我不知道的 GWT。

任何帮助,将不胜感激

谢谢

4

3 回答 3

12

我得到这个工作的方式如下:我写了一个jsni方法来打开一个新窗口

public static native BodyElement getBodyElement() /*-{
        var win = window.open("", "win", "width=940,height=400,status=1,resizeable=1,scrollbars=1"); // a window object
        win.document.open("text/html", "replace");

我在新窗口中添加了一个基本主体并返回了 body 元素

win.document.write("<HTML><HEAD>"+css1+css2+"</HEAD><BODY><div class=\"mainpanel\"><div style=\"width: 100%; height: 54px;\"><div id=\"mainbody\"class=\"mainbody\" style=\"width: 100%;\"></div></div></div></BODY></HTML>");
        win.document.close(); 
        win.focus();
        return win.document.body;
    }-*/;

然后我从我的主要 java 方法中调用了这个方法

BodyElement bdElement = getBodyElement();

然后我将包含许多小部件的面板注入到返回的正文元素中

SystemConfiguration config = new SystemConfiguration();             bdElement.getOwnerDocument().getElementById("mainbody").appendChild(config.getElement());
于 2010-11-17T13:56:12.683 回答
1

I agree with Bogdan: Use a DialogBox.

If you can't, you Window.open() as you mentioned in option 1:

  1. Create another GWT module, and form.html that will load it
  2. Window.open("form.html?entry=54")
  3. Have the form gwt module read from the URL, load the entry, allow it to be edited, and provide Save and Cancel buttons
  4. Close the popup when Save or Cancel is clicked
于 2010-11-12T19:03:58.697 回答
0

你不能只使用一个对话框吗?

例子

于 2010-11-12T18:25:35.157 回答