如何在GWT中将自定义HTML元素注册为窗口小部件

嗨大家有没有人知道如何将自定义html元素注册为GWT小部件uiBinder并直接使用它们代替在 HTMLPanel中使用.

对于例如如果我在mgwt项目中使用Google Polymer我正在使用自定义html元素

<g:HTMLPanel >
                    <paper-shadow class="{style.card}">
                        <mgwt:touch.TouchPanel ui:field="touchPanel">
                            <mgwt:panel.flex.FlexPanel orientation="VERTICAL" alignment="CENTER">
                                <g:Image url="{global.getDirection.getSafeUri.asstring}" />
                                <g:HTMLPanel>Take me to Deal</g:HTMLPanel>
                            </mgwt:panel.flex.FlexPanel>
                        </mgwt:touch.TouchPanel>
                    </paper-shadow>
                </g:HTMLPanel>

我想注册/创建纸质阴影作为自定义小部件,以便我可以编写代码,以便它容易handel事件

<polymer:paper-shadow class="{style.card}">
                    <mgwt:touch.TouchPanel ui:field="touchPanel">
                        <mgwt:panel.flex.FlexPanel orientation="VERTICAL" alignment="CENTER">
                            <g:Image url="{global.getDirection.getSafeUri.asstring}" />
                            <g:HTMLPanel>Take me to Deal</g:HTMLPanel>
                        </mgwt:panel.flex.FlexPanel>
                    </mgwt:touch.TouchPanel>
                <polymer:paper-shadow>

解决方法

据我所知,你不能轻易添加UiBinder会理解的新自定义元素.但是,您可以添加一个your custom widget.

您会注意到GWT允许这些自定义元素的自定义属性,如DockLayoutPanel

<g:DockLayoutPanel unit='EM'>
  <g:north size='5'>
    <g:Label>Top</g:Label>
  </g:north>
  <g:center>
    <g:Label>Body</g:Label>
  </g:center>
  <g:west size='192'>
    <g:HTML>
      <ul>
        <li>Sidebar</li>
        <li>Sidebar</li>
        <li>Sidebar</li>
      </ul>
    </g:HTML>
  </g:west>
</g:DockLayoutPanel>

注意< g:north size ='5'> element – 如果你查看DockLayoutPanel的源代码,你会发现它是由这个方法处理的:

public void addnorth(Widget widget,double size) {
    insert(widget,Direction.norTH,size,null);
}

没有@UiChild注释和额外的参数意味着在场景背后发生了“神奇”的事情.确实如此,有一个DockLayoutPanelParser类来处理这种特殊情况.您会注意到它实现了ElementParser – 不幸的是,it’s not possible to “plug in” your own ElementParser.

一个项目,gwt-customuibinder,试图回避这个限制,但它已被弃用为较新的(2.5?)版本的GWT:

Please note that with the newer releases of GWT,this project is Now deprecated as many of the techniques used to add custom element parsers to UiBinder are Now not possible.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些