0

我想从 GWTBootstrap3 子类化(扩展)模态小部件,以创建可以在我的应用程序中重用的自定义模态小部件。使用 UiBinder 时我不知道该怎么做。我只能在 java 代码中创建 ModalHeader、ModalBody 和 ModalFooter 并使用 add(Widget) 方法添加它们。

但是我怎样才能为我的子类使用 UiBinder 呢?

4

1 回答 1

0

您可以在 UiBinder 代码中使用您的自定义小部件。这就是你的目的吗?只需将自定义小部件所在的包导入单独的命名空间即可。假设小部件WeatherReport在包com.my.app.widgets中,并且您要使用的命名空间是my,导入如下所示:

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:my="urn:import:com.my.app.widgets">

现在您可以像这样在 UiBinder 代码中添加WeatherReport对象:

<g:HTMLPanel>
    <my:WeatherReport ui:field="weather" />
</g:HTMLPanel>

有关更多信息,请参阅官方 GWT 文档

在 UiBinder 中使用ModalHeaderModalBody等的工作方式相同。导入相应的包并使用组件,这里是一个简单的例子:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
        xmlns:g="urn:import:com.google.gwt.user.client.ui"
        xmlns:b="urn:import:org.gwtbootstrap3.client.ui">
        <b:ModalBody>
                <b:Row>
                        <b:Column size="MD_12">
                                <b:Input ui:field="passwordInput" type="PASSWORD" />
                        </b:Column>
                </b:Row>
                <b:ModalFooter">
                        <b:Button ui:field="saveButton" text="Save" type="PRIMARY" />
                        <b:Button ui:field="cancelButton" text="Cancel" />
                </b:ModalFooter>
        </b:ModalBody>
</ui:UiBinder>
于 2015-02-17T13:22:53.870 回答