We use DWR to invoke the remote method to involve the data conversion between JS and JAVA parameters and return values, for example:
The conversion between JS 123 and Java int or Integer, long
The conversion between JS "2009-06-23" and Java java.util.Date
Conversion between JS "[1,2,3]" and Java int[]
JS "{id:123, Name: ' Unmi '}" and Java Class person{int ID; Conversion between String name}
or more complex nested types ("{id:123, Name: ' Unmi ', blogs: [' http://unmi.blogjava.net ', ' Http://blog.csdn.net/kypfos ']}") and conversions between Java types Wait a minute. So how did all this happen? In fact, we have seen a lot of component type mappings, such as Java PropertyEditor, Hibernate (usertype), IBatis (Typehandler) type mappings, STRUTS1/2 used in Form/model Converter and so on.
Here I will analyze the Converter implementation of DWR and explain how to customize my Converter. The DWR used in this article is the 2.0.5 version.
1. DWR built-in Converter and application types
Name |
Type of application |
Converters |
Null |
Void,java.lang.void |
Nullconverter |
Enum |
|
Enumconverter |
Primitive |
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 |
Primitiveconverter |
BigNumber |
Java.math.biginteger,java.math.bigdecimal |
Bignumberconverter |
String |
Java.lang.String |
Stringconverter |
Array |
[z,[b,[s,[i,[j,[f,[d,[c,[l* |
Arrayconverter |
Map |
Java.util.Map |
Mapconverter |
Collection |
Java.util.Collection |
Collectionconverter |
Date |
Java.util.date,java.sql.date, Java.sql.Time,Java.sql.Timestamp, Java.util.Calendar |
DateConverter |
Dom |
Org.w3c.dom.node,org.w3c.dom.element, Org.w3c.dom.Document |
Domconverter |
dom4j |
Org.dom4j.document,org.dom4j.element, Org.dom4j.Node |
Dom4jconverter |
Jdom |
Org.jdom.document,org.jdom.element |
Jdomconverter |
Xom |
Nu.xom.document,nu.xom.element, Nu.xom.Node |
Xomconverter |
Servlet |
Javax.servlet.ServletConfig, Javax.servlet.ServletContext,Javax.servlet.http.HttpServletRequest, Javax.servlet.http.HttpServletResponse, Javax.servlet.http.HttpSession |
Servletconverter |
Bean |
|
Beanconverter |
Object |
|
Objectconverter |
Hibernate2 |
|
H2beanconverter |
Hibernate3 |
|
H3beanconverter |
Url |
Java.net.URL |
Urlconverter |
exception |
|
Exceptionconverter |
Miniexception |
Java.lang.Throwable |
Minimalistexceptionconverter |