dojox.grid.DataGrid populated from Servlet

Posted by jeff porter on Stack Overflow See other posts from Stack Overflow or by jeff porter
Published on 2010-05-25T11:02:59Z Indexed on 2010/05/31 1:12 UTC
Read the original article Hit count: 589

Filed under:
|

I'd like to hava a Dojo dojox.grid.DataGrid with its data from a servlet.

Problem: The data returned from the servlet does not get displayed, just the message "Sorry, an error has occured".

If I just place the JSON string into the HTML, it works. ARRRRGGH.

Can anyone please help me!

Thanks Jeff Porter

Servlet code...

public void doGet(HttpServletRequest req, HttpServletResponse resp) {
    res.setContentType("json");
    PrintWriter pw = new PrintWriter(res.getOutputStream());
    if (response != null) pw.println("[{'batchId':'2001','batchRef':'146'}]");
    pw.close();
}

HtmL code...

    <div id="gridDD" dojoType="dojox.grid.DataGrid" 
    jsId="gridDD" style="height: 600x; width: 100%;" 
    store="ddInfo" structure="layoutHtmlTableDDDeltaSets">
    </div>      

    var rawdataDDInfo = ""; // empty at start
    ddInfo = new dojo.data.ItemFileWriteStore({
        data: {
            identifier: 'batchId',
            label: 'batchId',
            items: rawdataDDInfo
        }
    });
    <script>
    function doSelectBatchsAfterDate() {
    var xhrArgs = {
        url: "../secure/jsonServlet",
        handleAs: "json",
        preventCache: true,
        load: function(data) {
        var xx =dojo.toJson(data);
            var ddInfoX = new dojo.data.ItemFileWriteStore({data: xx});
            dijit.byId('gridDD').setStore(ddInfoX);
        },
        error: function(error) {
                alert("error:" + error);
        }
    }

    //Call the asynchronous xhrGet
    var deferred = dojo.xhrGet(xhrArgs);
    }
    </script>
<img src="go.gif" onclick="doSelectBatchsAfterDate();"/>

© Stack Overflow or respective owner

Related posts about dojo

Related posts about dojox.grid.datagrid