【问题标题】:GWT UiBinder not showing anythingGWT UiBinder 没有显示任何内容
【发布时间】:2013-11-30 10:18:18
【问题描述】:

我是 GWT 的新手。我刚开始为我的大学做一个简单的 GWT 论坛作为项目。我无法让 UiBinder 正常工作。我认为显示代码是解释我的问题的最佳方式。

Header.ui.xml

<g:DockLayoutPanel>
    <g:west size="5">
        <g:Label ui:field="forumTitle"/>
    </g:west>
</g:DockLayoutPanel>

Header.java

package com.project.gwtforum.client.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class Header extends Composite{

    private static HeaderUiBinder uiBinder = GWT.create(HeaderUiBinder.class);

    interface HeaderUiBinder extends UiBinder<Widget, Header> {
    }

    public Header() {
        initWidget(uiBinder.createAndBindUi(this));
    }

    @UiField
    Label forumTitle;

    public Label getForumTitle() {
        return forumTitle;
    }
}

GWTForum.html

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <link type="text/css" rel="stylesheet" href="GWTForum.css">

    <script type="text/javascript" language="javascript" src="gwtforum/gwtforum.nocache.js"></script>

  </head>

  <body>

    <div id="header"></div>

    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

  </body>
</html>

GWTForum.css

h1 {
  font-size: 2em;
  font-weight: bold;
  color: #777777;
  margin: 40px 0px 70px;
  text-align: left;
}

GWTForum.java

package com.project.gwtforum.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.project.gwtforum.client.widgets.Header;

public class GWTForum implements EntryPoint{

    private GWTForumConstants constants = GWT.create(GWTForumConstants.class);
    private Header headerWidget = new Header();

    @Override
    public void onModuleLoad() {
        initializeLayout();
    }

    private void initializeLayout() {
        RootPanel.get("header").add(headerWidget);
        Window.setTitle(constants.windowTitle());

        headerWidget.getForumTitle().setText(constants.windowTitle());
        headerWidget.getForumTitle().setStyleName("h1");
    }

}

问题是当我编译一个项目时浏览器中什么都没有。当我调试应用程序时,我可以看到 RootPanel 正在改变——其中的代码是正确的,但浏览器什么也没显示。 Firebug 还看到带有标签等的“标题”div,但没有显示任何内容。 Firefox 的“显示源代码”在“标题”div 中没有任何内容。我做错了什么?

【问题讨论】:

    标签: gwt uibinder docklayoutpanel


    【解决方案1】:

    您正在混合布局 (DockLayoutPanel) 和非布局 (RootPanel.get("header")) 面板。

    要么使用RootLayoutPanel(这将钩住你的应用程序的整个主体;因此你需要重写它来设置你的应用程序内部的页眉/主/页脚区域,而不是依赖DOM 占位符)或显式设置 header 大小。请参阅official docs

    我会选择前者。

    【讨论】:

    • 我在文档中错过了这一点。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2020-03-24
    • 2014-07-21
    • 2016-02-19
    • 2020-06-16
    • 2021-02-05
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多