The 'new' Creator

The new creator is declared by default by DWR as follows: <creator id="new" class="uk.ltd.getahead.dwr.create.NewCreator"/> You don't need to add this line to your dwr.xml because it is already in the DWR's internal dwr.xml file.

This creator will create an instance of a class using the default constructor. There are several benefits to using the 'new' creator:

  • Security: The shorter lived the objects created by DWR the less chance that they can be exploited by loading them up with invalid values in one call and then the invalid values fired at something that wasn't expecting it in another.
  • Low memory overhead: If you have a site with many users, then you don't run the risk of running out of VM memory so much

You allow DWR to use the new creator to create and remote your beans as follows:

<allow>
  <create creator="new" javascript="Blah">
    <param name="class" value="java.util.Date"/>
  </create>
  ... 
</allow>

This remotes java.util.Date to Javascript and gives it the name Blah so in Javascript when you call Blah.toString(reply) then a new java.util.Date will be constructed using the default constructor, then the toString() method will be called, and the data returned to the javascript reply function (in this case the current date in string form).