Analysis of DWR Util.js package __js

Source: Internet
Author: User
Analysis Dwr Util.js Package

From: http://www.blogjava.net/liuwentao253/archive/2006/08/21/64797.html

Let's briefly introduce what is DWR

Dwr-direct Web Remoting

Ajax is a way to write Web pages that improve the attractiveness and practicality of web sites. It updates the special area of the Web page from the server side , thereby enhancing user interactivity. It allows information to be updated in a short time delay or without refreshing the page.

DWR reduces development time and also reduces possible errors that arise when you provide commonly used method functions and eliminate repetitive code related to highly interactive web sites.

DWR is available for free as an open-source software (ASL verssion 2.0). It is very easy to implement with its vast libraries, examples, and guides. It is very simple to combine it with an existing site, and it can be simply combined with most Java frameworks.

Util.js Util.js contains some of the methods used to help you use JavaScript (possibly) to update your Web data from the server side.

You can use it outside of DWR because it does not depend on the DWR.

It contains four page-processing functions: 1 getText () acting on the select lists. 2 Getvalue[s] (), Setvalue[s] () acts on most HTML elements except tables, lists, and images. 3 Addrows () and removeallrows () are used to edit tables. 4 addoptions () and removealloptions () are used to edit lists (for example: select Lists, UL, OL).

$ (): $ function (in JavaScript, whose name is legal) is introduced from the prototype. Generally, $ = document.getElementById. When you spend a lot of time doing AJAX programming in the future, it's good to use this format in the right place.

' $ ' finds an element in the current HTML page with the given ID, and if more than one argument is committed, it returns an array containing the found elements. This function is inspired by the prototype library, and it works better in different browsers.

One: A feature of generating Lists dwr can add options to a drop-down list (select list) using only 1 dwrutil.addoptions ()

If you want to keep some options before updating the list, you need to write the following code: 1 var sel = dwrutil.getvalue (ID); 2 dwrutil.removealloptions (ID); 3 dwrutil.addoptions (ID,); 4 Dwrutil.setvalue (ID, SEL);

If you want to have an initialization option, such as: "Please select", you can use directly: 1 dwrutil.addoptions (ID, ["Please select"]);

Two: Dwrutil.addoptions has 5 methods of invocation: 1:array:dwrutil.addoptions (Selectid, Array). Selectid is the text for the target Id,array for each item.

2:array of objects (option Text = option value): Dwrutil.addoptions (Selectid, data, prop) creates a set of text and value for each array element To build an option, the Pro parameter specifies the value of text and value.

3:array of objects (with differing option text and value): Dwrutil.addoptions (Selectid, Array, Valueprop, Textprop) Use the collection of text and value to create an option for each array element, valueprop OK value,textprop determine text.

4:object:dwrutil.addoptions (Selectid, map, reverse) creates an option for each property in the map, the property name as the value of the option, and the value of the property as the text of the option.       This may seem wrong, but in practice it is true. If the reverse parameter is set to True, the value of the property is still the value of the option being used.

5:map of Objects:DWRUtil.addOptions (Selectid, Map, Valueprop, Textprop) creates an option for each object in the Map Valueprop the value,text of the specified option Prop specifies the text of the option.

Three: Generating Tables

Dwrutil.addrows () Gets the value from an array (the second argument) and creates each row of the table. The value from another array (the third argument) creates several columns for each row of the table.

Four: Dwrutil.gettext (ID)

You can get the value of text based on the ID, this method can only be used for select list

Five: Dwrutil.getvalue (ID)

You can get value based on the ID, and using this method, you don't have to care about the difference between div and select list.

VI: Dwrutil.getvalues ()

GetValues () is similar to GetValue () except this input is a Javascript object that contains Name/value. The names are assumed to is the IDs of HTML elements, and the values are altered to reflect the contents of those. This is does not return the object in question, it alters the value of this

This method is the same as GetValue (), except that it passes in a JavaScript object that contains a name and a numeric value. The name is the ID of the HTML element. This method will not return any objects, it will only map the ID value to the passed-in value. Example:  1 function dogetvalues ()   { 2       var text =   "{& Nbsp;3       div:null,  4       textarea:null, & Nbsp;5       select:null,  6       text:null,  7       password:null,  8       formbutton : null,  9       button:null 10} ";  //JavaScript Object var object  =  objecteval (text);    dwrutil.getvalues ( object); var reply  =  dwrutil.todescriptivestring (object,  2);   //Goto REP ly  =  reply.replace (//n/g,  "<br/>");     //Show DWRUTil.setvalue ("Getvaluesret",  reply);                      21 22}

Seven: Dwrutil.onreturn

Paste a piece of code, temporarily do not understand, with OnReturn and do not have what difference 1 < script > 2 function submitfunction () {3 $ ("alert"). Style.display =  "Inline";  4 settimeout ("Unsubmitfunction ();", 1000);  5} 6 7 function unsubmitfunction () {8 $ ("alert"). Style.display = "None"; 9 </script > < p >< input type = "text" onkeydown = Dwrutil.onreturn (event, Submitfunctio N) "/> < input type =" button "onclick =" submitfunction () "VALUE =" Go "/> < span id =" Alert "style =" display:none; Background: #FFFFDD; Font-weight:bold; "> Submitfunction called </span > </p >

Eight: Dwrutil.selectrange

In an input box, select a range of 1 dwrutil.selectrange ("Sel-test", $ ("Start"). Value, $ ("End"). value);

Nine: Dwrutil.setvalue (ID, value)

Find the element with ID and update value

Ten: Dwrutil.setvalues ()

Just like SetValue (Id,value), the only parameter it needs is a JavaScript object, such as:

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.