延迟绑定异常GWT自定义小部件到UIBinder

时间:2013-04-27 07:39:10

标签: gwt

我是Gwt的新手,正在寻找uibinder

    <!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"
            xmlns:my = "urn:import:com.kt.outdoor.media.client.view">

    <g:DockLayoutPanel unit='EM'>
        <g:north size='5'>
            <g:FlowPanel styleName="{style.northPanel}">
                <my:Menu ui:field="hello"></my:Menu>
            </g:FlowPanel>
        </g:north>
    </g:DockLayoutPanel>
</ui:UiBinder>`

package com.kt.outdoor.media.client.view;

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

public class Menu<T> extends Composite implements MenuView<T> {

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

    interface MenuUiBinder extends UiBinder<Widget, Menu> {
    }

    private Presenter<T> presenter;

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

    @Override
    public void setPresenter(Presenter<T> presenter) {
        this.presenter = presenter;
}

    public Widget asWidget() {
        return this;
    }

}

例外是

Caused by: com.google.gwt.event.shared.UmbrellaException: Exception caught: Deferred binding failed for 'com.kt.outdoor.media.client.view.Menu' (did you forget to inherit a required module?) 
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129) 
at com.google.gwt.user.client.impl.HistoryImpl.fireEvent(HistoryImpl.java:80) 
at com.google.gwt.event.logical.shared.ValueChangeEvent.fire(ValueChangeEvent.java:43) 
at com.google.gwt.user.client.impl.HistoryImpl.fireHistoryChangedImpl(HistoryImpl.java:87) at com.google.gwt.user.client.History.fireCurrentHistoryState(History.java:131) 
at com.kt.outdoor.media.client.AppController.go(AppController.java:58)
at com.kt.outdoor.media.client.OutDoor_Media.onModuleLoad(OutDoor_Media.java:16)
... 9 more
Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.kt.outdoor.media.client.view.Menu' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53) at com.google.gwt.core.shared.GWT.create(GWT.java:57)
at com.google.gwt.core.client.GWT.create(GWT.java:85)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.build_hwllo(Home_HomeUiBinderImpl.java:108)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.get_hwllo(Home_HomeUiBinderImpl.java:104)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.build_f_FlowPanel2(Home_HomeUiBinderImpl.java:93)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.get_f_FlowPanel2(Home_HomeUiBinderImpl.java:87)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.build_f_DockLayoutPanel1(Home_HomeUiBinderImpl.java:73)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.get_f_DockLayoutPanel1(Home_HomeUiBinderImpl.java:67)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl$Widgets.access$0(Home_HomeUiBinderImpl.java:66)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl.createAndBindUi(Home_HomeUiBinderImpl.java:15)
at com.kt.outdoor.media.client.view.Home_HomeUiBinderImpl.createAndBindUi(Home_HomeUiBinderImpl.java:1)
at com.kt.outdoor.media.client.view.Home.(Home.java:23)
at com.kt.outdoor.media.client.AppController.onValueChange(AppController.java:70)
at com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch(ValueChangeEvent.java:128) 
at com.google.gwt.event.logical.shared.ValueChangeEvent.dispatch(ValueChangeEvent.java:1) 
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
... 15 more
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:513)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
... 35 more

任何人都可以告诉我我的代码有什么问题。

提前致谢

这是演示者代码,我不明白为什么会失败。

package com.kt.outdoor.media.client.presenter;

import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window;

import com.google.gwt.user.client.ui.HasWidgets;
import com.kt.outdoor.media.client.event.ButtonClickEvent;
import com.kt.outdoor.media.client.view.MenuView;

public class MenuPresenter<String> implements Presenter, MenuView.Presenter<String>{


private final HandlerManager eventBus;
private final MenuView<String> view;

public MenuPresenter(HandlerManager eventBus, MenuView<String> view) {

    this.eventBus = eventBus;
    this.view = view;

    this.view.setPresenter(this);

}

@Override
public void onMenuButtonClicked() {
    Window.alert("Hello!");
    eventBus.fireEvent(new ButtonClickEvent());

}

@Override
public void go(HasWidgets container) {
    container.clear();
    container.add(view.asWidget());

}

}

根据要求附加了演示者代码

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。这就是我解决它的方式。首先检查您的.gwt.xml

中是否已有此条目
<source path='client'/>
<source path='shared'/>

如果已经存在,请检查您是否使用了最新的xerces jar。 我的问题通过从xerces / xercesImpl.jar-2.6.2更新到xercesImpl.jar来解决 - 2.9.1
这是我在GWT Compile期间遇到的错误。

     java.lang.AbstractMethodError: 
     org.apache.xerces.dom.ElementNSImpl.setUserData(Ljava/lang/ 
     String;Ljava/lang/Object;Lorg/w3c/dom/UserDataHandler;)Ljava/lang/ 
     Object; 
     at com.google.gwt.uibinder.rebind.W3cDocumentBuilder.startElement(W3cDocumentB 
uilder.java:130)

您可以从http://mojo.codehaus.org/gwt-maven-plugin/dependencies.html

下载jar

让我知道这是否有效!

答案 1 :(得分:0)

它与您的项目设置有关。 stacktrace中的主要问题是GWT编译器没有查找com.kt.outdoor.media.client.view.Menu类所在的gwt.xml模块。请仔细检查您的GWT模块xml文件设置,或者更好地将您的项目布局和gwt.xml发布到您的问题中。