首页 文章

如何为整个GWT页面手动重置HTML?

提问于
浏览
0

我有一个MyArticlePresenter.java(在客户端包中) . 它的网址是“mydomain.com#!article”:

MyArticlePresenter.java有一个RPC来调用文章 . 我希望在从数据库获取articleData后,它将清除该GWT页面中的所有内容,然后将整个GWT页面重置为新的 <html>

private AsyncCallback<GetArticleResult> getArticleCallback=new AsyncCallback<GetArticleResult>(){
    @Override
public void onSuccess(GetArticleResult result) {
        String articleData=result.getArticleData;

        RootPanel.getBodyElement().setInnerHTML("<html>"+articleData+"</html>");

    }
}

但是,我收到了一个错误 .

Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (String) @com.google.gwt.http.client.URL::encodeQueryStringImpl(Ljava/lang/String;)([string: 'chz']): invoke of @com.google.gwt.http.client.URL::encodeQueryStringImpl(Ljava/lang/String;) failed
    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:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.http.client.URL.encodeQueryStringImpl(URL.java)
    at com.google.gwt.http.client.URL.encodeQueryString(URL.java:325)
    at com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter.escape(ParameterTokenFormatter.java:198)
    at com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter.toPlaceToken(ParameterTokenFormatter.java:190)
    at com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter.toHistoryToken(ParameterTokenFormatter.java:122)
    at com.gwtplatform.mvp.client.proxy.PlaceManagerImpl.updateHistory(PlaceManagerImpl.java:492)
    at com.gwtplatform.mvp.client.proxy.ProxyPlaceAbstract$3$1.execute(ProxyPlaceAbstract.java:208)
    at com.google.gwt.core.client.impl.SchedulerImpl$Task$.executeScheduled$(SchedulerImpl.java:50)
    at com.google.gwt.core.client.impl.SchedulerImpl.runScheduledTasks(SchedulerImpl.java:180)
    at com.google.gwt.core.client.impl.SchedulerImpl.flushPostEventPumpCommands(SchedulerImpl.java:345)
    at com.google.gwt.core.client.impl.SchedulerImpl$Flusher.execute(SchedulerImpl.java:78)
    at com.google.gwt.core.client.impl.SchedulerImpl.execute(SchedulerImpl.java:138)
    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: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:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    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:347)
    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.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)

你能找到一个优雅地重置整个GWT页面的方法吗?

1 回答

  • 0

    看来这是解决方案:

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
    
                    @Override
                    public void execute() {
                        RootPanel.getBodyElement().setInnerHTML("<html>"+articleData+"</html>");
                    }
              });
    

相关问题