GWT

时间:2016-07-14 16:07:47

标签: gwt frame onload-event

我正在创建一个包含Frame小部件的DialogBox。我已经尝试使用addLoadHander和addAttachHandler钩子来尝试捕获对帧的更改但没有成功。只有初始页面加载才会触发任一事件,经过一些研究后,似乎实际上在Widget连接到DOM时实际发生,而不是在加载帧内容时。

DialogBox paymentProcessingDialog = new DialogBox(false);
private void submitPayment(String actionURL, String qryString){     
    Frame processCCWindow = new Frame(actionURL + "?" + qryString);     
    processCCWindow.addLoadHandler(new LoadHandler() {
        @Override 
        public void onLoad(LoadEvent event) {
            //This is called when the frame is attached to the dom
            //and not when the document is actually ready so it's 
            //kinda worthless for my scenario
            //Note: the addAttachHandler has the same issue

            //***call to JSNI idea (see below)
            checkURLChange();
        }

    });
    //...irrelevant code to style the DialogBox
    VerticalPanel panel = new VerticalPanel();
    panel.add(processCCWindow);
    paymentProcessingDialog.setWidget(panel);
    paymentProcessingDialog.center();
    paymentProcessingDialog.show();
}

加载到框架中的URL包含来自外部服务器的HTML响应(Paypal - 透明重定向),它立即通过表单重新提交回我的服务器。一旦提交回我的服务器并且框架中的文档已经加载,我试图捕获框架的主体。

我还尝试使用一个使用MutationObserver(got the code from this solution)来尝试观看框架的JSNI方法,但我相信JSNI实际上是在父内部运行而不是在框架内运行(?)所以没有任何反应。

我还尝试使用setTimeout在我的演示者类中触发另一个方法但是我认为它遇到了与MutationObserver想法相同的问题,因为控制台语句永远不会触发。

    private static native void checkURLChange()/*-{
  new MutationObserver(function(mutations) {
      mutations.some(function(mutation) {
        if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
          console.log(mutation);
          console.log('Old src: ', mutation.oldValue);
          console.log('New src: ', mutation.target.src);
          return true;
        }

        return false;
      });
    }).observe(location.href, {
      attributes: true,
      attributeFilter: ['src'],
      attributeOldValue: true,
      characterData: false,
      characterDataOldValue: false,
      childList: false,
      subtree: true
    });
    window.location = "foo";
    setTimeout(function() {
        @com.myPackage.MyoutPresenter::paymentProcessComplete(Ljava/lang/String;)(document.getElementsByTagName("body")[0].innerText);
      console.log("test" + document.getElementsByTagName("body")[0].innerText);
    }, 3000);
}-*/;

有没有人对如何做到这一点有任何想法?

1 个答案:

答案 0 :(得分:1)

我不熟悉Frame小部件,但是在设置URL之后,您似乎添加了一个处理程序。尝试首先构建Frame(如果您多次使用它,则在submitPayment之外),然后设置URL:

final Frame processCCWindow = new Frame();     
processCCWindow.addLoadHandler(new LoadHandler() {
    @Override 
    public void onLoad(LoadEvent event) {
        // do something
    }

});

private void submitPayment(String actionURL, String qryString){
    processCCWindow.setUrl(actionURL + "?" + qryString);
}