当我第一次打开“ EditAwardsView1”时,Window.alert显示一次。输入数据,选择“保存”按钮,然后保存到数据库一次。到目前为止,一切都很好。

但是,然后我回到上一个视图“ SelectPerson”,然后再次打开“ EditAwardsView1”。这次Window.alert显示两次,并且出现一个“未捕获的异常转义”错误。我输入数据,选择“保存”按钮,然后我两次保存到数据库。

如果我再次重复此操作(返回到“ SelectPerson”,然后再返回到“ EditAwardsView1”),Window.alert显示五次,并且出现四个“未捕获的异常转义”错误。我输入数据,选择“保存”按钮,我保存到数据库的操作进行了五次。

“ SelectPerson”视图中的调用代码为:

btnEditAward.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        navHandler2.go("EditAwards1");
    }
});
btnEditAward.setStyleName("gwt-PushButton-up");
btnEditAward.setText("Edit Awards");
btnEditAward.setWidth("184px");
btnEditAward.setHeight("40px");
horizontalPanel.add(btnEditAward);


“ EditAwards1”中的入口点是:

public EditAwardsView1(final NavHandler navHandler) {

    rpc = (DBConnectionAsync) GWT.create(DBConnection.class);
    ServiceDefTarget target = (ServiceDefTarget) rpc;
    String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
    target.setServiceEntryPoint(moduleRelativeURL);

    navHandler2 = navHandler;

    //On load of page get the stored view data
    //TODO Fix null pointer on reload.
    verticalPanel.addAttachHandler(new Handler() {
        int pog = 0;
        public void onAttachOrDetach(AttachEvent event) {
            if (pog == 0) {
                pog++;
                verticalPanel.clear();
                listBoxAwardType.clear();
                awardGrouped = null;
                Window.alert("EditAwardsView1.");

                //Retrieve stored data for this view.
                AsyncCallback<ViewData> callback = new ViewDataHandler2<ViewData>(EditAwardsView1.this);
                rpc.getViewData(callback);

            }else{
                pog = 0;
            }
        }
    });
    initWidget(verticalPanel);
}


从“ EditAwardsView1”返回到“ SelectPerson”视图的调用代码是:

//Button btnSelectYouthMember = new Button("Select Youth Member");
        btnSelectYouthMember.setStyleName("gwt-PushButton-up");
        btnSelectYouthMember.setText("Select Youth Member");
        btnSelectYouthMember.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                navHandler2.go("SelectPerson");
            }
        });
        btnSelectYouthMember.setWidth("184px");
        btnSelectYouthMember.setHeight("40px");
        horizontalPanel_Menu.add(btnSelectYouthMember);


错误是:

[ERROR] [org.AwardTracker.AwardTracker] - Uncaught exception escaped


15:58:18.009 [ERROR] [org.AwardTracker.AwardTracker] Uncaught exception escaped

com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.core.client.impl.Impl::apply(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)([JavaScript object(12426), JavaScript object(2059), JavaScript object(12432)]): Unable to set property 'onfocus' of undefined or null reference
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
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:242)
at sun.reflect.GeneratedMethodAccessor23.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:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:299)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.user.client.Window.alert(Window.java)
at org.AwardTracker.client.EditAwardsView1$3.onAttachOrDetach(EditAwardsView1.java:131)
at com.google.gwt.event.logical.shared.AttachEvent.dispatch(AttachEvent.java:100)
at com.google.gwt.event.logical.shared.AttachEvent.dispatch(AttachEvent.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.logical.shared.AttachEvent.fire(AttachEvent.java:52)
at com.google.gwt.user.client.ui.Widget.onAttach(Widget.java:351)
at com.google.gwt.user.client.ui.Composite.onAttach(Composite.java:162)
at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:475)
at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:127)
at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:97)
at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:97)
at org.AwardTracker.client.NavHandler.go(NavHandler.java:53)
at org.AwardTracker.client.SelectPersonView$ViewDataHandler$2.onClick(SelectPersonView.java:131)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:56)
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.GeneratedMethodAccessor28.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:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
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:242)
at sun.reflect.GeneratedMethodAccessor23.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:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)

最佳答案

请参阅http://forums.whirlpool.net.au/forum-replies.cfm?t=2265752以获得答案。

简而言之,我:
删除了NavHandler.java,
更改了AwardTracker.java以允许历史记录并消除对NavHandler.java的需要,
更改了对History.newItem(“ selectPerson”,true)的新视图调用;
将测试if(event.isAttached())添加到AttachHandler并
将以下代码移到AttachHandler中-
    rpc =(DBConnectionAsync)GWT.create(DBConnection.class);
    ServiceDefTarget target =(ServiceDefTarget)rpc;
    字符串moduleRelativeURL = GWT.getModuleBaseURL()+“ MySQLConnection”;
    target.setServiceEntryPoint(moduleRelativeURL);

问候,

格林

10-05 19:11