如何防止View在第一次调用后多次加载?

时间:2014-04-12 06:29:02

标签: java eclipse gwt

当我打开" EditAwardsView1" Window.alert第一次显示一次。我输入数据,选择"保存"按钮和我保存到DB一次。到目前为止一切都很好。

然而,我回到之前的观点" SelectPerson"然后打开" EditAwardsView1"第二次。这次Window.alert显示两次,我得到一个" Uncaught异常转义"错误。我输入数据,选择"保存"按钮和我保存到DB发生两次。

如果我再次重复此操作(返回" SelectPerson"然后返回" EditAwardsView1")Window.alert显示五次,我得到四次"未捕获的异常转义& #34;错误。我输入数据,选择"保存"按钮和我保存到数据库的次数发生了五次。

来自" 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);
}

来自&#34; EditAwardsView1&#34;的调用代码返回&#34; SelectPerson&#34;观点是:

//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)

1 个答案:

答案 0 :(得分:0)

请参阅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;     String moduleRelativeURL = GWT.getModuleBaseURL()+“MySQLConnection”;     target.setServiceEntryPoint(moduleRelativeURL);

问候,

格林