问题描述
在你开始击倒我之前,我已经检查了答案,我已经在谷歌上搜索,直到我的手指流血,但我还没有找到一个简单、简洁的答案.所以我再次询问所有可能遇到此问题的人.
Before you start shooting me down i have checked for answers and i have googled till my fingers bled but i havent been able to find a simple, concise answer. So im asking again for all those that might have this problem.
问题:如何打开一个带有模板面板的新窗口.
Question: how to open a new window with a formpanel in side.
上下文:我有一个列出了很多项目的应用程序,我想让某人编辑一个条目,我想要一个新窗口打开以便他们可以编辑属性然后点击保存.您可以在许多应用程序中找到标准的东西.
Context: i have an app that lists lots of items, i want someone to edit an entry, i want a new window to open so they can edit properties then hit save. A standard thing you find in a lot of applications.
架构:我有一个名为 UI 的客户端模块,它有十几个类,可以在从菜单中选择时绘制小部件并填充主区域.我有一个名为 UI.html 的 html 页面,它的头部有标签.就是这样.
Architecture:I have one client module called UI, it has a dozen classes that draw widgets and fill a main area when selected from a menu. I have a single html page called UI.html which has the tag in the head. Thats it.
我见过的选项
调用 Window.Open() 但您需要定义一个 html 文件.我没有.我可以创建一个空的,但是如何向其中注入一个小部件?
Call Window.Open() but you need to define a html file. I dont have one. I can create an empty one but how do you inject a widget in to it ?
使用 jsni $wnd 创建一个新窗口并获取对它的引用.但是我如何将表单面板注入其中?
use jsni $wnd to create a new window and get a reference to it. But how do i inject a form panel into it ??
使用弹出面板.它们看起来很糟糕 - 另外,如果通过 JS 打开一个窗口很简单,我希望它在 gwt 中.
use a popuppanel. They look sucky - plus if opening a window through JS is quite simple i would expect it to be in gwt.
也许我想念我不知道如何使用 GWT.
Maybe im miss understanding how to use GWT i dont know.
任何帮助将不胜感激
谢谢
推荐答案
我的工作方式如下:我写了一个jsni方法来打开一个新窗口
The way i got this to work is as follows:i wrote a jsni method to open a new window
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 并返回了 body 元素
i added a basic body to the new window and returned the body element
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 方法中调用了这个方法
i then called this method from my main java method
BodyElement bdElement = getBodyElement();
然后我将包含许多小部件的面板注入到返回的 body 元素中
I then injected my panel which has lots of widgets into the returned body element
SystemConfiguration config = new SystemConfiguration(); bdElement.getOwnerDocument().getElementById("mainbody").appendChild(config.getElement());
这篇关于在 GWT 中打开带有小部件的新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!