DWR Note 2

Source: Internet
Author: User
Matching Java objects with JavaScript objects
Public Class Remote {
Public void setperson (person p ){
This. Person = P;
}
}

And classes person looks like this:
Public person {
Private string name;
Private int age;
Private date [] appointments;
// Getters and setters... be sure to add getter and setter
}

// Then you can call this from JavaScript like this:
VaR P = {
Name: "Fred Bloggs ",
Age: 42,
Appointments: [new date (), new date ("1 Jan 2008")]
};
Remote. setperson (P );

Because setperson () is modified using void, callback is not required in Javascript, even if you write a callback function
And DWR will not pass any value back.
You can also write
Remote. setperson (null, P );

Asynchronous loading prompt
The DWR standard displays Gmail-style loading message prompts. You can call
The loading message prompts, but it cannot be called before page onload. Because the loading principle still uses an hide
To accommodate loading messages.
In DWR, you can complete the Gmail-style loading settings with only one simple step.
<Head>
<SCRIPT>
Function Init (){
Dwrutil. useloadingmessage ();
}
</SCRIPT>
...
</Head>
<Body onload = "Init ();">

Of course, you may not be able to modify the <body> element in the CMS mode.
<SCRIPT>
Function Init (){
Dwrutil. useloadingmessage ();
}

If (window. addeventlistener ){
Window. addeventlistener ("LOAD", init, false );
}
Else if (window. attachevent ){
Window. attachevent ("onLoad", init );
}
Else {
Window. onload = Init;
}
</SCRIPT>

You can also dynamically create a layer (with ID = "disabledzone") that contains a prompt message.
Below are two improved programs

The first one allows you to modify your own prompt message
Function useloadingmessage (Message ){
VaR loadingmessage;
If (Message) loadingmessage = message;
Else loadingmessage = "loading ";

Dwrengine. setprehook (function (){
VaR disabledzone = $ ('disabledzone ');
If (! Disabledzone ){
Disabledzone = Document. createelement ('div ');
Disabledzone. setattribute ('id', 'disabledzone ');
Disabledzone. style. Position = "absolute ";
Disabledzone. style. zindex = "1000 ";
Disabledzone. style. Left = "0px ";
Disabledzone. style. Top = "0px ";
Disabledzone. style. width = "100% ";
Disabledzone. style. Height = "100% ";
Document. Body. appendchild (disabledzone );
VaR messagezone = Document. createelement ('div ');
Messagezone. setattribute ('id', 'messagezone ');
Messagezone. style. Position = "absolute ";
Messagezone. style. Top = "0px ";
Messagezone. style. Right = "0px ";
Messagezone. style. Background = "red ";
Messagezone. style. color = "white ";
Messagezone. style. fontfamily = "Arial, Helvetica, sans-serif ";
Messagezone. style. Padding = "4px ";
Disabledzone. appendchild (messagezone );
VaR text = Document. createtextnode (loadingmessage );
Messagezone. appendchild (text );
}
Else {
$ ('Messagezone'). innerhtml = loadingmessage;
Disabledzone. style. Visibility = 'visable ';
}
});

Dwrengine. setposthook (function (){
$ ('Disabledzone '). style. Visibility = 'ddn ';
});
}

2nd images can be used as prompt messages
Function useloadingimage (imagesrc ){
VaR loadingimage;
If (imagesrc) loadingimage = imagesrc;
Else loadingimage = "ajax-loader.gif ";
Dwrengine. setprehook (function (){
VaR disabledimagezone = $ ('disabledimagezone ');
If (! Disabledimagezone ){
Disabledimagezone = Document. createelement ('div ');
Disabledimagezone. setattribute ('id', 'disabledimagezone ');
Disabledimagezone. style. Position = "absolute ";
Disabledimagezone. style. zindex = "1000 ";
Disabledimagezone. style. Left = "0px ";
Disabledimagezone. style. Top = "0px ";
Disabledimagezone. style. width = "100% ";
Disabledimagezone. style. Height = "100% ";
VaR imagezone = Document. createelement ('img ');
Imagezone. setattribute ('id', 'imagezone ');
Imagezone. setattribute ('src', imagesrc );
Imagezone. style. Position = "absolute ";
Imagezone. style. Top = "0px ";
Imagezone. style. Right = "0px ";
Disabledimagezone. appendchild (imagezone );
Document. Body. appendchild (disabledimagezone );
}
Else {
$ ('Imagezone'). src = imagesrc;
Disabledimagezone. style. Visibility = 'visible ';
}
});
Dwrengine. setposthook (function (){
$ ('Disabledimagezone'). style. Visibility = 'hiddy ';
});
}

Dwrutil. todescriptivestring () is used for any HTML control on the debug page.
Dwrutil. todescriptivestring (P1, P2)
P1 indicates the ID of the control you want to bebug
P2 (Int = {0, 1, 2 })
Where 0, the single line debugging information is returned.
1/2 return multi-line debugging information
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.