The script engine. js contains the core part of DWR. Generally, your application should include it.
Util. JS is usually included, which contains some optional practical methods.
Demo. JS is dynamically defined in DWR. It also contains a corresponding remote version called demo. java. If you see
The following code:
Demo. Method1 = function {callback, P0}
Demo. method2 = function {callback}
So we can see that the first parameter is the callback function, and P0 is probably the parameter you want to return.
Common Methods in engine. js include:
Dwrengine. seterrorhandler (function) handle errors
Dwrengine. setwarninghandler (function) handle warnings
Dwrengine. setTimeout () sets the timeout time.
Because "A" in Ajax refers to asynchronous (asynchronous), every demo. Method execution is asynchronous.
If you want to specify global timeout settings, you can use dwrengine. setTimeout () to complete
Similarly, dwrengine. seterrorhandler (function), dwrengine. setwarninghandler (function)
Used to set global error and warning handling
Of course, if you want to handle a function timeout, warning, or error
As follows:
Demo. Method (Params ,{
Callback: function (data) {alert ("It worked ");},
Errorhandler: function (Message) {alert ("It broke ");},
Timeout: 1000
});
DWR can capture custom error exceptions such as: Implemented in errdemo. Java
Public class errdemo {
Public String getdata (){
Throw new nullpointerexception ("message ");
}
}
Call in customer segment
Function EH (MSG) {// Error Function
Alert (MSG );
}
Dwrengine. seterrorhandler (EH );
Errdemo. getdata (function (data) {alert ("123 ");});
The result of the program is that eh jumps out of the dialog box. At this time, MSG is quite called.
Exception. getmessage () method value
This is also acceptable if you want to capture custom exceptions.
Public class errdemo {
Public String getdata (){
Date when = new date (); // funkyexception extend exception
Throw new funkyexception ("message", when );
// Implement getwhen () method in funkyexception
}
}
Client
Function EH (MSG, ex ){
Alert (MSG + ", date =" + ex. When );
}
Dwrengine. seterrorhandler (EH );
Errdemo. getdata (function (data) {alert ("123 ");});
The displayed dialog box contains "message, date = mon Jan 01 2008 10:00:00 GMT + 0100"