Dojo is a good thing, but it is really not easy to make full use of it. Many controls and things are involved.
There is a certain amount of time required. A previous company project was a boss website. The customer service had high requirements on AJAX because it had to be operated frequently,
So Ajax is needed, especially for refreshing. It uses dojo + DWR + spring, and the front end is completely dojo. It is a completely static page. Of course it is still a bit Javascript. DWR + spring is a good backend combination, dojo + DWR + spring can be used sometimes
It completely replaces struts, but the effect is as follows. Now let's take an example to explain it quickly. This article requires the basic knowledge of DWR to look like
It is much more convenient.
The example is a temporary example. You can delete and modify it. First, check the static page bbslist.htm.
<Script language = "JavaScript" type = "text/JavaScript" src = "DWR/engine. js"> </SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript" src = "DWR/util. js"> </SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript" src = "DWR/interface/BBS. js"> </SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript" src = "dojo. js"> </SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript" src = "JS/mootools. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Dojo. Require ("dojo. widget. Dialog ");
</SCRIPT>
First, we introduced the DWR, The JS file of dojo, And the dialog box Effect of dojo,
<Table> 〉
<Thead>
<! -- List header -->
<Tr>
& Lt; th width = "50%" Height = "13" & gt;ArticleTitle </Th>
<TH width = "12%"> author </Th>
<TH width = "18%"> latest reply time </Th>
<TH width = "14%"> latest responder </Th>
<TH width = "6%"> replies </Th>
</Tr>
</Thead>
<! -- Display Record Content -->
<Tbody id = "recorddata"> </tbody>
<! -- Display paging information -->
<Tbody id = "rollpageinfo"> </tbody>
<Script language = "JavaScript" type = "text/JavaScript" src = "tousu/BBS/bbslist. js"> </SCRIPT>
Here, only the list header is provided. recorddata and rollpageinfo are dynamically filled in through moontools, dojo, DWR, and so on.
Okay, now the front-end list page is like this. Next, let's take a look at the DWR, dojo, and moontools sections. First, let's look at the auxiliary file bbslist. js. Its function is to receive frontend input and transmit it to backend spring using DWR,
VaR smscontentconfigquery = {
// Define the method: Query Based on the conditions entered by the user
Querybycon: function (){
Setroweff. orow = NULL; // clear the current row
Pageinfobean. pageno = 1; // set the page number to 1
Getlist ();
}
};
/Query Functions
Function getlist (){
Useloadingmsg (""); // display the prompt message "loading data. Please wait ......"
// Query based on the query conditions entered by the user. The gotlist is the callback function.
Bbslist = NULL;
BBS. getbbslist (..., gotlist );
}
// Callback function
Function gotlist (item ){
Dwrutil. removeallrows ("recorddata"); // clear all previous records
// If no data is returned (item = NULL), it ends.Program
If (item = NULL ){
Return;
}
Dwrutil. addrows ("recorddata", item. bbslist, cellfunctions, options );
Bbslist = item. bbslist;
// When a page is loaded,
Dojo. addonload (
Function (){
Smscontentconfigquery. querybycon (); // query based on user input conditions
}
);
The meaning here is actually the function of loading smscontentconfigquery. querybycon () by dojo first,
In querybycon (), you can perform some initial settings, and then in BBS. getbbslist (..., gotlist );
In fact, DWR calls the back-end spring for processing. For example, it returns the news list in the form of map,
After the result is returned, it is processed by calling the callback function gotlist ().
Here, item can be understood as the result set returned by the backend. Observation
Dwrutil. addrows ("recorddata", item. bbslist, cellfunctions, options );
Where is item. bbslist?
In fact, if the backend spring returns a list and a map, bbslist is its name, such as the backend:
Rethashmap. Put ("bbslist", bbslist );
Do you understand?
Cellfuntions, what is options? This is defined in DWR.
VaR cellfunctions = []; // defines an array and stores the function name of the read object attribute.
Cellfunctions = [gettitle, GetUserName, getlast_time, getlast_name, getcount];
// Define the function for reading Object Attributes
// Read Record ID
Function getsysid (item ){
Return item. sysid;
}
// Read the ticket number
// Read the range of available cities
Function getcontent (item ){
Return item. content;
}
Function GetUserName (item ){
Return item. Username;
}
Function gettitle (item ){
// For excellent posts
If (item. is_key = 1)
{
Return "}
Else
{
Return item. title;
}
}
Function getcontent (item ){
Return item. content;
}
Function getcount (item ){
Return item. count;
}
Function getwrite_time (item ){
Return item. write_time;
}
Function getlast_time (item ){
Return item. last_time;
}
Function getlast_name (item ){
Return item. last_name;
}
Function getis_key ()
{Return item. is_key;
}
Finally, dwrutil. addrows ("recorddata", item. bbslist, cellfunctions, options );
In "recorddata", do you see it? DWR fills the data retrieved from the backend into the static page.
<Tbody id = "recorddata"> </tbody>
The news list is displayed.
Conclusion: dojo + DWR + spring is good if it is used in some occasions, but you should pay attention to complicated situations, such as one-to-many.
In this case, it is not necessarily easy to use methods like DWR + dojo. Instead, it is sometimes better to use struts and jstl as the front-end,
at least it is convenient for the artist to implement it. In this case, too many brains may be required for Ajax. Therefore, I personally think that
DWR serves as a bridge in the end. Its advantage is that it exposes backend JavaBean, spring, and other things directly as front-end JavaScript,
it reduces the effort to write JavaScript, but it is not very appropriate to use DWR for front-end display like this. It requires too much skill.
there are many dojo controls, and sometimes the results are good. Others use too much, not necessarily good, and consume too much memory.
next time I will continue to explain how to add, delete, and modify dojo + DWR + spring.