DWR Converters

本文介绍DWR中预定义的各种数据类型转换器,包括null、primitive、string、date等,及其默认配置方式,帮助开发者理解DWR如何处理不同类型的Java对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值