问题描述
我一直在尝试撰写。使用gwt-platform的示例我已经成功地使用手动显示来获取联系人视图来获取联系人列表,我正在尝试使用UiHandlers添加按钮,但它并未在我的ContactsPresenter的onAddButtonClicked()中调用该方法。
休耕是我认为的代码片段
显然 getUiHandlers()是 null ...但是你知道: - )
我想这可能是因为你忘记了在注入相关演示者时设置UI处理程序(这将是n
public class ContactsPresenter扩展了Presenter< ContactsPresenter.MyView,ContactsPresenter.MyProxy>
implements ContactsViewUiHandlers
{
public interface MyView extends View,HasUiHandlers {/ * nothing * /}
私人PlaceManager placeManager;
@Inject
ContactsPresenter(最终EventBus eventBus,最终MyView视图,
最终MyProxy代理,最终PlaceManager placeManager)
{
super(eventBus,view , 代理 );
this.placeManager = placeManager;
getView()。setUiHandlers(this);
}
...
@Override
public void onAddButtonClicked()
{
placeManager.revealPlace(new PlaceRequest(somewhereovertheocean ));
}
...
}
(执行部分 getView()。setUiHandlers(this); 和 implements ContactsViewUiHandlers <顺便说一句,最好在执行前检查 getUiHandlers()以获得null-ness调用任何方法...
希望有帮助。
干杯,
I've been trying to write contacts. example using gwt-platform I've successfully got the contacts view using manual reveal to obtain contacts list, I'm trying to use UiHandlers for add button but it is not calling the method in my ContactsPresenter's onAddButtonClicked().
fallowing is the code snippet of my view
public class ContactsView extends ViewWithUiHandlers<ContactsViewUiHandlers> implements ContactsPresenter.MyView { private final Widget widget; @UiField Button addButton; @UiHandler("addButton") public void onAddButtonClick(ClickEvent e){ System.out.println("add button clicked"); getUiHandlers().onAddButtonClicked(); }}
fallowing is UiHandlers interface
public interface ContactsViewUiHandlers extends UiHandlers{ void onAddButtonClicked(); }and in my presenter i'm firing an event with event bus in onAddButtonClicked().
but the control is not coming to my presenter and i'm getting the following exception when i'm clicking the add button.
[ERROR] [contactsgwtp] - Uncaught exception escaped 10:17:10.527 [ERROR] [contactsgwtp] Uncaught exception escaped 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.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129) at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116) at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177) at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351) at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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.GeneratedMethodAccessor28.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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(Thread.java:662) Caused by: java.lang.NullPointerException: null at com.saik.in.client.core.ContactsView.onAddButtonClick(ContactsView.java:51) at com.saik.in.client.core.ContactsView_BinderImpl$1.onClick(ContactsView_BinderImpl.java:50) at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54) at com.google.gwt.event.dom.client.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.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129) at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116) at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177) at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351) at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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.GeneratedMethodAccessor28.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) 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(Thread.java:662)any suggestions on what i'm missing, thanks in advance
解决方案Obviously getUiHandlers() is null... But you knew that :-)
I would expect the cause of this could be that you have forgotten to set the UI handlers when injecting in the associated presenter (which would be the normal procedure in GWTP) - something like:
public class ContactsPresenter extends Presenter<ContactsPresenter.MyView, ContactsPresenter.MyProxy> implements ContactsViewUiHandlers { public interface MyView extends View, HasUiHandlers { /* nothing */ } private PlaceManager placeManager; @Inject ContactsPresenter( final EventBus eventBus , final MyView view , final MyProxy proxy , final PlaceManager placeManager ) { super( eventBus , view , proxy ); this.placeManager = placeManager; getView().setUiHandlers( this ); } ... @Override public void onAddButtonClicked() { placeManager.revealPlace( new PlaceRequest( "somewhereovertheocean" ) ); } ... }(The operative part being getView().setUiHandlers( this ); and implements ContactsViewUiHandlers).
Incidentally, it is good practice to always check getUiHandlers() for null-ness before invoking any methods on it...
Hope that helps.
Cheers,
这篇关于如何使用GWT平台的UiHandlers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!