0

我有一个 GWT 项目,我想知道 GWT 如何创建 HTML5标签。

经过几个小时的搜索,我来这里问,有没有办法用 GWT 构建 HTML5 部分标签?

4

3 回答 3

1

是的,您可以创建自己的小部件。

public class SectionPanel extends ComplexPanel implements
    InsertPanel.ForIsWidget {
/**
 * Creates an empty section panel.
 */

public SectionPanel() {
 setElement(DOM.createElement("section"));
}

/**
 * Adds a new child widget to the panel.
 * 
 * @param w
 *            the widget to be added
 */
@Override
public void add(Widget w) {
    add(w, getElement());
}

... etc. ...

}

于 2013-01-30T09:10:31.893 回答
1

无需创建新的小部件类型 - 您只需使用泛型HTMLPanel并指定要使用的标签。

UiBinder 选项

如果您使用UiBinder,您的.ui.xml文件将包含如下内容:

<!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">
    ...
    <g:HTMLPanel tag="section">
        (your section content here)
    </g:HTMLPanel>
    ...
</ui:UiBinder>

手动选项

如果您更喜欢以编程方式执行此操作:

HTMLPanel section = new HTMLPanel("section", "(your section content here)");

第一个参数指定您要使用的标签;如果您未指定第一个参数,则默认值为div.

在这两种情况下,它都会在您的 HTML 输出中生成:

<section>
    (your section content here)
</section>
于 2016-03-09T01:09:39.707 回答
0

你可以在 Ui:Binder 中添加任何你喜欢的 HTML:

https://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder

于 2013-01-30T16:24:21.050 回答