Creating a dwr.xml file
dwr.xml has the following structure:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<!-- init is only needed if you are extending DWR -->
<init>
<creator id="..." class="..."/>
<converter id="..." class="..."/>
</init>
<!-- without allow, DWR isn't allowed to do anything -->
<allow>
<create creator="..." javascript="..."/>
<convert converter="..." match="..."/>
</allow>
<!-- you may need to tell DWR about method signatures -->
<signatures>
...
</signatures>
</dwr>
Terminology
Some terminology worth understanding - parameters are converted, but the remoted beans are created. So if you have a bean A with a method A.blah(B) then you need a creator for A and a converter for B.
<allow>
The allow section defines which classes DWR can create and convert.
Creators
Each class on which we execute methods, needs a <create ...> entry. There are several types of creator. The most common ones use either the 'new' keyword or the Spring framework. For more information, see the Creator documentation.
Converters
We need to ensure that all the parameters can be converted. Many of the types provided by the JDK are enabled for you, but you need to give DWR permission to convert your own code. Generally this means that JavaBean parameters will need a <convert ...> entry.
By default all of the following are converted for you without further declaration:
· All primitive types, boolean, int, double, etc.
· The Class based versions of the these Boolean, Integer, etc.
· java.lang.String
· java.util.Date and the 3 SQL derivatives
· arrays of the above
· Collections (Lists, Sets, Maps, Iterators, etc) of the above
· DOM objects (like Element and Document) from DOM, XOM, JDOM and DOM4J
For details on how to convert your own JavaBeans and other parameters see the Converter documentation.
<init>
The optional init section declares the classes that can be used to create beans to remote and the classes that can be used to convert beans in the marshalling process. For most cases you will not need to use it. If you wish to define a new Creator [JavaDoc] or Converter [JavaDoc] it needs to be declared here, but do double-check on the ones that are currently available first.
Having an entry in the init section just tells DWR about the existence of the class and gives it some basic detail about how it works. It does not bring it into use. In this way it is a bit like an import statement in Java. Most classes must be imported before use, but just having an import does not mean that the class is being used. Each creator and converter has an id attribute to allow it to be referred to later on.
<signatures>
DWR uses reflection to find out what types it should use in the conversion process. Sometimes the type information is not available, in which case you can type the method signatures in here to give it a hint. See the signatures section for more detail.
Multiple dwr.xml Files
There can be more than one dwr.xml file (see the web.xml documentation for more details). The entries in each are added together. This ability is used by DWR to load the basic config file to get everyone started.
We can get a good introduction to dwr.xml files by looking at the standard config file that everyone gets for free.
Labels:
Trackback: http://cwq.iou1314.com/_a148
Trackback: http://cwq.iou1314.com/_a148




















