Converters are an integral part of DWR and are responsible for marshaling data between the client and the server. You must specify a converter for:
A number of converters deserve sections of their own:
- Array Converter
- Bean and Object Converters
- Collection Converter
- File Converter (from DWR 3.0)
- Enum Converter
- DOM Objects
- See also Hibernate Intergration
- And Servlet Objects (HttpServletRequest, HttpSession, etc)
The converters for primitives, strings and simple objects like BigDecimal are all there waiting for you. You don't need a
<convert ...> element in the
<allow> section in dwr.xml to use them - They are enabled by default.
The types enabled by default include: boolean, byte, short, int, long, float, double, char, java.lang.Boolean, java.lang.Byte, java.lang.Short, java.lang.Integer, java.lang.Long, java.lang.Float, java.lang.Double, java.lang.Character, java.math.BigInteger, java.math.BigDecimal, java.util.Collection (implemenations), java.util.Map (implemenations), java.lang.String, etc. For a complete list you can take a look at the dwr.xml which defines all of the default converters (in the dwr.jar).
java.sql.Timestamp. As with the basic converters above, the DateConverter is enabled by default.
Date.parse() and then pass it to the server using DWR's DateConverter, or pass it as a String and then parse it in Java using a SimpleDateFormat (or something similar).
It is fairly simple to create your own converter. The Javadoc for the Converter interface contains instructions. It quite rare however for this to be needed. Please make sure you understand the BeanConverter before starting to write your own Converter. Having implemented a custom converter, you need to register it with DWR. If you are using dwr.xml, there is an <init> section before the <allow> that lets you register new components. See the DTD documentation for more information.