2012-05-10 9 views
0

SmartGWT 3.0とGWTP 0.7を使用しています。SmartGWT WindowとPresenterWidgetを使用したGWTPエラー

SmartGWTウィンドウを表示する簡単なPresenterWidgetを実行しようとしています。これは、ウィジェットのプレゼンターのためのコードです:

import com.gwtplatform.mvp.client.PresenterWidget; 
import com.gwtplatform.mvp.client.PopupView; 
import com.google.inject.Inject; 
import com.google.web.bindery.event.shared.EventBus; 

public class DemoWidgetPresenter extends 
    PresenterWidget<DemoWidgetPresenter.MyView> { 

public interface MyView extends PopupView { 
} 

@Inject 
public DemoWidgetPresenter(final EventBus eventBus, final MyView view) { 
    super(eventBus, view); 
} 

@Override 
protected void onBind() { 
    super.onBind(); 
} 

@Override 
protected void onReveal() { 
    super.onReveal(); 
    System.out.println(">>>> onReveal()"); 
} 
} 

そしてビューコード:

import com.gwtplatform.mvp.client.PopupViewImpl; 
import com.google.inject.Inject; 
import com.google.web.bindery.event.shared.EventBus; 
import com.google.gwt.user.client.ui.Widget; 
import com.smartgwt.client.widgets.Window; 
import com.smartgwt.client.widgets.events.CloseClickEvent; 
import com.smartgwt.client.widgets.events.CloseClickHandler; 

public class DemoWidgetView extends PopupViewImpl implements 
    DemoWidgetPresenter.MyView { 

private Window winModal; 

@Inject 
public DemoWidgetView(final EventBus eventBus) { 
    super(eventBus); 

    winModal = new Window(); 
    winModal.setWidth(300); 
    winModal.setHeight(500); 
    winModal.setTitle("Export file"); 
    winModal.setShowMinimizeButton(false); 
    winModal.setIsModal(true); 
    winModal.setShowModalMask(true); 
    winModal.centerInPage(); 
    winModal.setCanDragResize(true); 
    winModal.addCloseClickHandler(new CloseClickHandler() { 
     @Override 
     public void onCloseClick(CloseClickEvent event) { 
      winModal.hide(); 
     } 
    }); 
} 

@Override 
public void center() { 
    winModal.centerInPage(); 
} 

@Override 
public void hide() { 
    winModal.hide(); 
} 

@Override 
public void setPosition(int left, int top) { 
    winModal.setLeft(left); 
    winModal.setTop(top); 
} 

@Override 
public void show() { 
    winModal.show(); 
} 

public Widget asWidget() { 
    return winModal; 
} 
} 

私はこのプレゼンターを表示し、プログラムの別の部分では: dpがあるaddToPopupSlot(dp, true);

注入されたDemoWidgetPresenterのインスタンス。

DemoWidgetPresenterはfolowing例外が発生示している。

com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full         set in UmbrellaException#getCauses 
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129) 
at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
at  com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337) 
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218) 
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) 
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) 
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 
at com.google.gwt.core.client.impl.Impl.apply(Impl.java) 
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213) 
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292) 
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546) 
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) 
at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.ClassCastException: com.smartgwt.client.widgets.Window cannot be cast to com.google.gwt.user.client.ui.PopupPanel 
at com.gwtplatform.mvp.client.PopupViewImpl.asPopupPanel(PopupViewImpl.java:130) 
at com.gwtplatform.mvp.client.PopupViewImpl.setCloseHandler(PopupViewImpl.java:104) 
at com.gwtplatform.mvp.client.PresenterWidget.monitorCloseEvent(PresenterWidget.java:574) 
at com.gwtplatform.mvp.client.PresenterWidget.addToPopupSlot(PresenterWidget.java:205) 
at com.demo.client.core.mvp.DiffPresenter$9.onClick(DiffPresenter.java:397) 
at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:96) 
at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.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) 
at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:67) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337) 
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218) 
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) 
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) 
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) 
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 
at com.google.gwt.core.client.impl.Impl.apply(Impl.java) 
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213) 
at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) 
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292) 
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546) 
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) 
at java.lang.Thread.run(Unknown Source) 

私は問題が com.smartgwt.client.widgets.Windowcom.google.gwt.user.client.ui.PopupPanel間鋳造によるものですが、私はそれを解決する方法がわからない参照してください! ..

任意のアイデア/回避策:-)を例外にもかかわらず

は、ウィンドウが表示されますが、機能onReveal()は呼び出すことはありませんので、プレゼンターライブサイクルが壊れていますか?

ありがとうございます!

+0

ここをクリックしてください:http://stackoverflow.com/a/10413533/92それがなぜ起こっているのかを理解するのに役立ちます –

答えて

2

私は、アダプタクラスをやって解決策を見つけた:

import com.google.gwt.event.logical.shared.CloseEvent; 
import com.google.gwt.event.logical.shared.CloseHandler; 
import com.google.gwt.event.shared.HandlerRegistration; 
import com.google.gwt.user.client.ui.PopupPanel; 
import com.gwtplatform.mvp.client.PopupView; 
import com.gwtplatform.mvp.client.PopupViewImpl; 
import com.smartgwt.client.widgets.Window; 
import com.smartgwt.client.widgets.events.CloseClickEvent; 
import com.smartgwt.client.widgets.events.CloseClickHandler; 

/** 
* Adapter class for {@link Window}. This class it is necessary when a 
* {@link PopupView} uses as widget a {@link Window}. GWTP library does an 
* explicit cast to {@link PopupPanel} in {@link PopupViewImpl} and a cast 
* exception is raised. This class adapts only these functions which are call in 
* {@link PopupViewImpl}. 
* 
* 
*/ 
public class PopupPanelAdapter extends PopupPanel { 

private Window delegate; 

public PopupPanelAdapter(Window delegate) { 
    this.delegate = delegate; 
    // adapting window close event 
    delegate.addCloseClickHandler(new CloseClickHandler() { 
     @Override 
     public void onCloseClick(CloseClickEvent event) { 
      CloseEvent.fire(PopupPanelAdapter.this, null); 
     } 
    }); 
} 

public void hide() { 
    delegate.hide(); 
} 

public void show() { 
    delegate.show(); 
} 

@Override 
public HandlerRegistration addCloseHandler(CloseHandler<PopupPanel> handler) { 
    return super.addCloseHandler(handler); 
} 

@Override 
public boolean isShowing() { 
    return isVisible(); 
} 

@Override 
public void center() { 
    delegate.centerInPage(); 
} 

@Override 
public void setPopupPosition(int left, int top) { 
    if (delegate == null)// call in constructor, delegate is null 
     return; 
    delegate.setLeft(left); 
    delegate.setTop(top); 
} 
} 

それが正常に動作します!

3

私の場合、レイアウトを定義するのにUIBinder XMLを使用していますが、私はGWTBootstrap3のModal compenentに問題がありました。

私が言及したソリューションを使用してカスタムModalPopupAdapterをロールアウトしたが、別の部分に以下の追加必要があった:ビューに

Javaコードを

@UiField(provided = true) 
Modal modal = new Modal(); 

@UiField(provided = true) 
ModalPopupAdapter modalPopupAdapter = new ModalPopupAdapter(modal); 

UiBinderサンプルメッセージのXML

<afr:ModalPopupAdapter ui:field="modalPopupAdapter"> 
    <bs:Modal ui:field="modal" other-attributes...> 
関連する問題