GWT:将 UIBinder 与 HTML 模板一起使用......如何让它工作?

标签 gwt uibinder

我目前正在尝试使用 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/

相关文章:

javascript - 如何将 JavaScriptObject 结果添加到 SmartGWT 中生成的 HTML 的特定位置?

java - CellTable 在 TabLayoutPanel 中不可见

gwt - CSS 类定义在 <g :HTML> element 内不起作用

gwtbootstrap 始终适用于所有元素

gwt - 单独的 GWT UIBinder 文件

java - Hibernate GWT 集成抛出 "java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z"

java - 单个 GWT 列表框不接受 CSS,但可以覆盖所有 GWT 列表框

javascript - GWT 代码分割同步请求

java - 是否可以通过 JUnit 测试使用 uiBinder XML 元素的方法?

java - Appengine 上传限制为 10000 个文件