DWR Converters

来源:互联网 发布:淘宝商城男运动鞋 编辑:程序博客网 时间:2024/05/16 00:37

Converters

Converters

The Converters

There are a number of converters that are defined and initialized for you. They are defined as follows:

<converter id="null"    class="uk.ltd.getahead.dwr.convert.NullConverter"/><converter id="primitive"    class="uk.ltd.getahead.dwr.convert.PrimitiveConverter"/><converter id="bignumber"    class="uk.ltd.getahead.dwr.convert.BigNumberConverter"/><converter id="string"    class="uk.ltd.getahead.dwr.convert.StringConverter"/><converter id="date"    class="uk.ltd.getahead.dwr.convert.DateConverter"/><converter id="array"    class="uk.ltd.getahead.dwr.convert.ArrayConverter"/><converter id="map"    class="uk.ltd.getahead.dwr.convert.MapConverter"/><converter id="collection"    class="uk.ltd.getahead.dwr.convert.CollectionConverter"/><converter id="bean"    class="uk.ltd.getahead.dwr.convert.BeanConverter"/><converter id="hibernate"    class="uk.ltd.getahead.dwr.convert.HibernateBeanConverter"/><converter id="dom"    class="uk.ltd.getahead.dwr.convert.DOMConverter"/><converter id="dom4j"    class="uk.ltd.getahead.dwr.convert.DOM4JConverter"/><converter id="jdom"    class="uk.ltd.getahead.dwr.convert.JDOMConverter"/><converter id="xom"    class="uk.ltd.getahead.dwr.convert.XOMConverter"/><converter id="servlet"    class="uk.ltd.getahead.dwr.convert.ServletConverter"/>

The converters are merely defined here and are put into use with <convert ...> elements. There are 2 attributes in any convert element, a reference to a converter definition and a match line that defines the class(s) that it can convert.

For example the simplest converter is the null converter that converts void and null values to javascript null and undefined vales. This creator is the simplest of all. It assumes that you will be calling static methods only, so no object creation is needed.

By default DWR marshalls Java void values into Javascript nulls using the following: <convert converter="null" match="void"/>. There are times when a java.lang.Void needs to be converted as well so the same converter is used for those too: <convert converter="null" match="java.lang.Void"/>. There is no danger in passing nulls from Java to Javascript so these definitions are made by default - you don't need to put them in the <allow> section yourself.

The primitive converter converts boolean, byte, char, etc as well as their Class based alternatives Boolean etc. The default setup includes 16 entries in the allow section for all primitive types along the following lines: <convert converter="primitive" match="java.lang.Long"/> and <convert converter="primitive" match="long"/>.

The string and date converters are also setup by default. We have not found any way to subvert Strings, Dates or basic numeric types so they are all turned on by default.