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

前端之家收集整理的这篇文章主要介绍了如何在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.

原文链接:https://www.f2er.com/html/225655.html

猜你在找的HTML相关文章