简体   繁体   English

子类化复合GWT小部件

[英]Subclass a composite GWT widget

I would like to subclass (extend) the Modal widget from GWTBootstrap3 to create a custom modal widget that can be reused within my app. 我想从GWTBootstrap3继承 (扩展) Modal小部件,以创建可在我的应用程序内重用的自定义模式小部件。 I don't know how to do this when using UiBinder. 使用UiBinder时我不知道该怎么做。 I can do it only in java code by creating a ModalHeader, a ModalBody and a ModalFooter and adding them using add(Widget) method. 我只能在Java代码中通过创建ModalHeader,ModalBody和ModalFooter并使用add(Widget)方法添加它们来做到这一点。

But how can I do the same using UiBinder for my subclass? 但是,如何为子类使用UiBinder进行相同操作?

You can use your custom widget in UiBinder code. 您可以在UiBinder代码中使用自定义窗口小部件。 Is that what you are up to? 那是你在做什么吗? Just import the package where your custom widget is into a separate namespace. 只需将自定义窗口小部件所在的包导入一个单独的命名空间即可。 Say the widget WeatherReport is in the package com.my.app.widgets and the namespace you want to use is my , the import looks like this: 假设小部件WeatherReportcom.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">

Now you can add WeatherReport objects in UiBinder code like this: 现在,您可以像这样在UiBinder代码中添加WeatherReport对象:

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

See the official GWT documentation for more information. 有关更多信息,请参见GWT官方文档

Using ModalHeader , ModalBody and so on in UiBinder works the same way. 在UiBinder中使用ModalHeaderModalBody等以相同的方式工作。 Import the respective package and use the components, here is a simple example: 导入相应的包并使用组件,这是一个简单的示例:

<!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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM