Search code examples
javajavascriptspringspring-mvcdwr

Make DWR pass a null value, rather than converting to false


I am working with DWR inside the context of a Spring 3.x Web MVC application, where my dwr-beans.xml file declares a bean like this:

<dwr:configuration>
    <dwr:convert type="bean" class="com.mypackage.Customer"/>
</dwr:configuration>

The com.mypackage.Customer class has one attribute of type Boolean (the object wrapper, not a boolean primitive).

This attribute has three different states that are meaningful to the business logic. It can be true or false, obviously... but a null value is meaningful for signaling that a selection hasn't be made yet.

Unfortunately, when a Java object is passed across to JavaScript through a DWR AJAX call... a null value shows up as false on the JavaScript object. I'm losing that third meaningful "neither of the above" state.

Google searching has not been very fruitful, unfortunately. Does anyone know if there is a way to make DWR properly pass across a Java null as a JavaScript null (or undefined)? Or might I be doing something wrong in the first place?


Solution

  • It turns out that DWR does handle null values correctly by default. My issue was further up the stack... not between the browser and the app server, but rather between the app server and the remote web service that it was calling for the data.