0

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?

Steve Perkins
  • 11,520
  • 19
  • 63
  • 95

2 Answers2

0

This is a piece of code, that can be found in PrimitiveConverter of DWR source code

if (paramType == Boolean.class)
{
    if (trimValue.length() == 0)
    {
        return null;
    }

    return (T) Boolean.valueOf(trimValue);
}

Whenever you pass null, asd or anything else you've get null as result. You can try to extend DWR with your own implementation, it could be rather tricky. Or use String instead in your bean with 3 state ("true", "false", "null").

Anton
  • 5,831
  • 3
  • 35
  • 45
  • Your last sentence is something that's crossed my mind, but I'm not sure where to begin as far as plugging a "custom converter" class into DWR somewhere... – Steve Perkins Apr 20 '12 at 19:04
0

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.

Steve Perkins
  • 11,520
  • 19
  • 63
  • 95