beebris
beebris

Reputation: 55

gwt using native javascript to send POST request for remote server fails

I am working on a GWT application that needs to send data to a remote cognos server to run a few reports. I am using native javascript code to send data but somehow cognos server doesn't receive all the data, we are sending large data as parameters in the URL. This is the code:

private static native void openReportWindow(String action, String uiObject, String reportName, String reportParams) /*-{
    var form = document.createElement("form");
    form.setAttribute("method", "POST");
    form.setAttribute("action", action);
    form.setAttribute("target", "reports");

    var reportValues = new Array();
    reportValues = reportParams.split('&');

    for(var i=0;i<reportValues.length;i++) {
        var tempArr = new Array();
        tempArr = reportValues[i].split('=');
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("name", tempArr[0]);
        hiddenField.setAttribute("value", tempArr[1]);
        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);

    // open a new window to display the reports
    window.open(action, 'reports', 'scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');
    form.submit();

}-*/;

Is there a better way to do this?

Thanks for all the help.

Upvotes: 1

Views: 965

Answers (1)

Daniel Kurka
Daniel Kurka

Reputation: 7985

You should not use JSNI to create and submit a form. You can do this with a complete Java API.

Anyhow if you are using JSNI to do so make sure to use $doc instead of document and $wnd instead of window to use the proper window and document object. (This has to do with different bootloaders and GWT and how your code has been loaded) Sometimes the window object will point to a child frame. $wnd and $doc are set by the compiler and will always point to the right one.

Remember there is no need to go to JSNI for what you are trying to do...

Upvotes: 1

Related Questions