JavaScript type of object returned by DWR

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JavaScript type of object returned by DWR

Bhavin Desai
Hi,

I'm new to DWR. I'm using DWR 3, the latest version. I'm trying something very simple but not getting to work. I've 2 classes

PersonCatalog
Person

dwr.xml contents:

    <create creator="new" javascript="PersonCatalog">
      <param name="class" value="dwrtest.PersonCatalog"/>
    </create>
    <convert converter="bean" match="dwrtest.Person" javascript="Person" />

index.html

PersonCatalog.get('bhavin', 'desai', {
  callback: function(obj) { 
    console.log(obj);
    console.log(typeof obj);
    console.log('instanceof MO: ' + obj instanceof Person);
  }
});

c {lastName: "desai", firstName: "bhavin"}
index.html:14 object
index.html:15 false
engine.js:979 Exception occured in user-specified handler:
engine.js:979 TypeError: obj.doSomething is not a function(…)

I was expecting JS typeof object to be Person and obj instanceof Person to be true. Please advise if I'm doing anything wrong or my expectation is wrong? I've tried both, bean and obj converters but get same results.

I've attached files for your reference.

Regards,
Bhavin Desai





index.html (714 bytes) Download Attachment
Person.java (644 bytes) Download Attachment
PersonCatalog.java (410 bytes) Download Attachment
dwr.xml (668 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: JavaScript type of object returned by DWR

Mike Wilson
Administrator
This should normally work but it is possible that you have done some overrides that affect the behaviour, f ex setting the web.xml init-param "generateDtoClasses".
 
Please post a reply to us with the following:
- your web.xml
- network trace (Firebug, Chrome dev tools etc) of DWR's PersonCatalog.get() reply
 
BTW, you can not call methods ("doSomething") on a value object.
 
Best regards
Mike Wilson
 
Bhavin Desai wrote:
Hi,

I'm new to DWR. I'm using DWR 3, the latest version. I'm trying something very simple but not getting to work. I've 2 classes

PersonCatalog
Person

dwr.xml contents:

    <create creator="new" javascript="PersonCatalog">
      <param name="class" value="dwrtest.PersonCatalog"/>
    </create>
    <convert converter="bean" match="dwrtest.Person" javascript="Person" />

index.html

PersonCatalog.get('bhavin', 'desai', {
  callback: function(obj) { 
    console.log(obj);
    console.log(typeof obj);
    console.log('instanceof MO: ' + obj instanceof Person);
  }
});

c {lastName: "desai", firstName: "bhavin"}
index.html:14 object
index.html:15 false
engine.js:979 Exception occured in user-specified handler:
engine.js:979 TypeError: obj.doSomething is not a function(…)

I was expecting JS typeof object to be Person and obj instanceof Person to be true. Please advise if I'm doing anything wrong or my expectation is wrong? I've tried both, bean and obj converters but get same results.

I've attached files for your reference.

Regards,
Bhavin Desai




Reply | Threaded
Open this post in threaded view
|

Re: JavaScript type of object returned by DWR

Mike Wilson
Administrator
I looked at your code again and spotted your mistake in this line:
    console.log('instanceof MO: ' + obj instanceof Person);
 
Operator precedence evaluates this as
    ('instanceof MO: ' + obj) instanceof Person
which checks instanceof on the resulting string expression.
 
You should use parentheseis to correct it:
    console.log('instanceof MO: ' + (obj instanceof Person));
 
As noted in my last mail, your call to obj.doSomething() is not supported as methods on value (converted) objects are not remoted.
 
Best regards
Mike
 
 
Mike Wilson wrote:
This should normally work but it is possible that you have done some overrides that affect the behaviour, f ex setting the web.xml init-param "generateDtoClasses".
 
Please post a reply to us with the following:
- your web.xml
- network trace (Firebug, Chrome dev tools etc) of DWR's PersonCatalog.get() reply
 
BTW, you can not call methods ("doSomething") on a value object.
 
Best regards
Mike Wilson
 
Bhavin Desai wrote:
Hi,

I'm new to DWR. I'm using DWR 3, the latest version. I'm trying something very simple but not getting to work. I've 2 classes

PersonCatalog
Person

dwr.xml contents:

    <create creator="new" javascript="PersonCatalog">
      <param name="class" value="dwrtest.PersonCatalog"/>
    </create>
    <convert converter="bean" match="dwrtest.Person" javascript="Person" />

index.html

PersonCatalog.get('bhavin', 'desai', {
  callback: function(obj) { 
    console.log(obj);
    console.log(typeof obj);
    console.log('instanceof MO: ' + obj instanceof Person);
  }
});

c {lastName: "desai", firstName: "bhavin"}
index.html:14 object
index.html:15 false
engine.js:979 Exception occured in user-specified handler:
engine.js:979 TypeError: obj.doSomething is not a function(…)

I was expecting JS typeof object to be Person and obj instanceof Person to be true. Please advise if I'm doing anything wrong or my expectation is wrong? I've tried both, bean and obj converters but get same results.

I've attached files for your reference.

Regards,
Bhavin Desai