Search code examples
arraylistdwr

parsing list of object in dwr


I have a remote function testdwr, which returns a list of objects(test). How should i parse the list of objects in the handler method? Code shown below

public List testdwr(String message) { Test test = new Test(); test.setName("mahati"); List arrayList = new ArrayList(); arrayList.add(test); return arrayList; }

handler method:

function update() { findaccounts.testdwr("somestring : ",function(data){ alert(data); }

the alert box gives the output as "object Object"!!


Solution

  • The ArrayList returned from the server will looks like,

    [Object { name="Mahati"}, Object { name="meena"}, Object { name="keerthi" }.....] 
    

    You can have a loop like this,

    for(var i=0; i<arrayList.length; i++)
    {
        var testObj = arrayList[i];
        //Here, you can do what you want! like...
        alert(testObj.name);
        alert(testObj.age);
    }
    

    Like Blake said, try to use FireBug, its an addon for firefox.