File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes DWR and JSON Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "DWR and JSON" Watch "DWR and JSON" New topic


Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I've been using DWR for a long time, and I'm a big fan! I love the way I can just call a JavaScript function that looks just like my Java Method.

The one area where I've had a little frustration is in working with 3rd party JavaScript Widgets. Many of them require a response in JSON. Is there any way to make DWR integrate with such widgets?

Consultant, Sima Solutions
Frank Zammetti
Ranch Hand

Joined: Dec 16, 2004
Posts: 136
I know that there is some work in the next version of DWR to use JSON rather than (or perhaps in addition to, not sure) the custom protocol DWR uses. That might help.

Short of that, I'd suggest a decent library to convert your objects to JSON. Most of the major libraries nowadays provide that functionality. You'll of course have to ensure your object model matches up with what the widgets expect so that conerted to JSON it'll be ready to go. Alternatively, provide a json field on your returned object that is generated via a getJson() method. That way, all your object you get back from DWR will have a JSON representation of themselves. This of course means you'll have to write the code to do that conversion, but that's not too difficult, and it'll let you ensure the JSON is in the format you need,

-- <br />Frank W. Zammetti<br />Founder and Chief Software Architect<br />Omnytex Technologies<br /><a href="" target="_blank" rel="nofollow"></a><br />AIM/Yahoo: fzammetti<br />MSN:<br />Author of "Practical Ajax Projects With Java Technology"<br /> (2006, Apress, ISBN 1-59059-695-1)<br />and "JavaScript, DOM Scripting and Ajax Projects"<br /> (2007, Apress, ISBN 1-59059-816-4)<br />Java Web Parts - <a href="" target="_blank" rel="nofollow"></a><br /> Supplying the wheel, so you don't have to reinvent it!
I agree. Here's the link:
subject: DWR and JSON
jQuery in Action, 3rd edition