我目前正在尝试使用 GWT 的 UIBinder 功能,但没有成功。我已多次阅读文档,但它不包含完整的故事。也许你可以帮助我。
到目前为止,这是我所知道的:
1)我需要创建例如一个 HelloWorld.ui.xml 文件,其中包含一些小部件布局。
2)我需要创建一个对应的HelloWorld类。
这是我找不到的信息:
A) 我将 HelloWorld.ui.xml 文件放在哪里,以使 GWT 能够找到它?
B)如何将我的 HelloWorld 组件添加到例如一个面板?
文档非常稀缺,并且肯定是由对 GWT 了解太多的人编写的,新手不知道的。
最佳答案
A) 你需要把 HelloWorld.ui.xml
与包含该 ui.xml 文件逻辑的小部件类在同一包中的文件。类名应为 HelloWorld
(为简单起见,我说您需要使用相同的名称,但可以通过代码为 ui.xml 文件使用不同的名称。)
B) 您的 HelloWorld
类应该是扩展小部件的类。就像任何“普通”小部件一样,它可以添加到任何面板中。
这是绑定(bind)HelloWorld.ui.xml
的代码在您的HelloWorld
小部件类:
public class HelloWorld extends Composite /*or extend any widget you want*/ {
//This defines an interface that represents this specific HelloWorld.ui.xml file.
interface MyUiBinder extends UiBinder<Widget, HelloWorld> {}
// This code is for GWT so it can generate the code from your HelloWorld.ui.xml
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
//Constructor
public HelloWidgetWorld() {
// This binds the HelloWorld.ui.xml with this widget
initWidget(uiBinder.createAndBindUi(this));
...
}
...
}
关于GWT:将 UIBinder 与 HTML 模板一起使用......如何让它工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4836568/