我正在使用SmartGWT 3.0和GWTP 0.7。
我正在尝试做一个显示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;
}
}
在程序的另一部分,我向这位演示者展示:
addToPopupSlot(dp, true);
其中dp
是DemoWidgetPresenter
的注入实例。
显示DemoWidgetPresenter
时会出现以下异常:
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.Window
和
com.google.gwt.user.client.ui.PopupPanel
但我不知道如何解决它!
尽管存在异常,但会显示窗口,但函数onReveal()
永远不会调用,因此演示者的实时循环会被破坏。
任何想法/解决方法: - )?
提前谢谢!
答案 0 :(得分:3)
在我的情况下,我们使用UIBinder XML来定义布局,我遇到了GWTBootstrap3的Modal功能问题。
我已经使用上述解决方案推出了自定义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...>
答案 1 :(得分: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);
}
}
一切正常!