繁体   English   中英

使窗口的行为类似于gwt中的消息框

[英]Make window behave like messagebox in gwt

因此,我有一个函数,如果发生某些情况,我需要显示一个带有窗体和某些字段的窗口。 而且,在关闭窗口之前,我不希望其余代码运行。 就像messageBox一样,但是里面还有一个表单。 据我所知messageBox很简单,这就是为什么我使用window。 但是window没有回调方法或使其余代码等待窗口关闭(隐藏)的方法。 我可能对此有错误的做法。 我愿意提出建议。 我宁愿继续将窗口类与modal = true一起使用。

我不知道这是否适合您的情况,但这就是我能够做到的方式。 需要注意的是, 我完全控制了表单提交中的服务器响应

首先,您可以在网页上公开可以通过本机javascript调用的方法。

public native void exportFormSubmissionProcessComplete(MyPresenter cop)/*-{
        $wnd.formSubmissionProcessComplete = $entry(function(result) {
            cop.@com.client.package.MyPresenter::formSubmissionProcessComplete(Ljava/lang/String;)(result);
        });
    }-*/;

然后创建您刚刚“导出”为JSNI的方法

private void formSubmissionProcessComplete(String result){
  if(result != null){
    //Process the results from where ever you submitted your form
  }
}

接下来,您将从表单提交中提取HTML响应以触发公开的JSNI方法。 (我使用的是Java Servlet,所以这是我的示例)

//...Arbitrary servelet processing code
response.setContentType("text/html");
response.getWriter().print("<!DOCTYPE html><head><title>FormProcessComplete</title>");
Map<String, String> data = parseData(buffer.toString());
  if(data.get(RESULT).equals("0")){
    //SUCCESS
    response.getWriter().print("<script type=\"text/javascript\">window.parent.formSubmissionProcessComplete(\"SUCCESS|" + data.toString().trim() + "\");</script>");
  }else{
    //FAIL
    response.getWriter().print("<script type=\"text/javascript\">window.parent.formSubmissionProcessComplete(\"FAIL|" + data.toString().trim() + "\");</script>");
  }
  response.getWriter().print("</head><body></body></html>");
//...Arbitrary servelet processing code

最后一步是将FormPanel小部件扔到Frame小部件中,并将FormPanel的目标设置为将根据上述示例生成HTML响应的服务器端点。 然后将您的Frame小部件显示在对话框中。

public static void submitForm(String actionURL, String qryString, DialogBox formProcessingDialog) {
        Frame processFormWindow = new Frame();
        processCCWindow.setSize("1px", "1px");
        formProcessingDialog.setGlassEnabled(true);
        formProcessingDialog.setText("Processing Form");
        VerticalPanel panel = new VerticalPanel();
        FormPanel form = new FormPanel();
        //Do whatcha gotta do to make your form here
        panel.add(processFormWindow);
        panel.add(form);
        formProcessingDialog.setWidget(panel);
        formProcessingDialog.center();
        formProcessingDialog.show();
        processFormWindow.setUrl(actionURL + "?" + qryString);
    }

这不是100%即插即用的,但是希望它将使您朝着适合您的方向前进。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM