DWR handles lists of primitives quite straight forward. I could not find whether array of objects returned by a DWR method call represent a JSON object. Any clues? Or do I have to return a JSON string representing the array of objects back to the browser?
DWR handles lists of primitives quite straight forward. I could not find whether array
Share
This answer is a little late, but here goes 🙂
Good news: DWR also handles Java arrays and Collections in a really straight-forward way. Just return them and on client side you’ll get JavaScript Array objects. (In typical cases like primitives or Strings inside your array or Collection, that is. If the contents is something more exotic, you may need to define converters; more below.)
Here’s a quote from DWR documentation (emphasis mine):
So you definitely won’t need JSON strings for these (although that may be a good option for more complicated data structures).
You can actually return many more kinds of objects without doing a lot of manual work because DWR comes with ‘converters‘ for lots of typical uses. For example, to make your custom ‘bean’ style Java objects work in client-side JS, all you need to say in
dwr.xmlis that you want to use the bean converter:Even if your method returns a List (or array) of those bean objects…
… the above configuration suffices, which is pretty nice.