1

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.

beebris
  • 55
  • 2
  • 9
  • You can create a Request from GWT Java code rather than dropping to JS, Have a look at the GWT RPC examples about talking to a JSON server. – John3136 Jul 12 '12 at 23:13
  • Thank you John3136. I did a rough research online, but it seems JSONP cannot be used to send a POST request, is that true? I need to send a POST request as my data exceeds 2083 chars - that needs to be sent as URL parameters to a cognos server. Pls note, I dont need to process a response from the server, I just need to send a one way request. Thanks! – beebris Jul 13 '12 at 00:24
  • You can have a look at [Post data to JsonP][1] question. [1]: http://stackoverflow.com/questions/2699277/post-data-to-jsonp – Arcadien Jul 16 '12 at 09:31
  • Thank you Arcadien. But I have no control over the server unfortunately, I can't add a page there to handle the JSONP requests unfortunately. I also read http://stackoverflow.com/questions/9811478/can-i-do-a-jsonp-request-with-post?lq=1. All I need to do is send large amount of data to a cognos server to create a report, I also don't need a response from the server. Thanks. – beebris Jul 16 '12 at 23:04

1 Answers1

1

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...

Daniel Kurka
  • 7,973
  • 2
  • 24
  • 43
  • I'm still a newbie. What other alternatives are there to JSNI? I've looked at using RequestBuilder or XMLHttpRequest but both doesn't work because of SOP policy. I'm open to any suggestions... Thank you heaps! – beebris Jul 15 '12 at 22:39