大家好,有人知道如何将自定义 html 元素注册为 GWT 小部件 uiBinder 并直接使用它们而不是在 HTMLPanel 中使用吗。
例如如果我使用 Google Polymer在我的 mgwt项目我使用自定义 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>
我想注册/创建 paper-shadow 作为自定义小部件,这样我就可以编写代码以便于处理事件
<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'>
元素 - 如果你查看 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.
关于java - 如何在 GWT 中将自定义 HTML 元素注册为小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27287348/