Jaxcent Ajax development framework learning notes

Source: Internet
Author: User

Jaxcent Ajax development framework learning notes

 

-- I accidentally saw an Ajax development framework named jaxcent on the Internet the day before yesterday. After reading the official documents, I thought it was a bit interesting. So I came back to try it and thought it really had a meaning, in small-scale web/Ajax application development, especially in small teams with independent designers and programmers, it can indeed improve productivity. So I learned and noted down my understanding of this framework.

* Due to the short term of access to Java (in fact less than three weeks), the understanding of Java itself and related tools in this article is limited, and errors and omissions are inevitable, which are to be corrected and improved.

 

---------------------
I. What can jaxcent do?
---------------------
Jaxcent is designed to provide a Java-based framework and API for Ajax programming and development.

 

"Jaxcent: Java-only Ajax programming. JavaScript programming not required !"

As stated in its official document, Javascript script programming is no longer necessary.


It should be noted that jaxcent is useful only when your Ajax application server is intended to be written in Java.

 

---------------------
Ii. Features of jaxcent
---------------------
1. stable and good versatility

 

1.1. It can be conveniently deployed in any container or application server that supports Java Servlet.
1.2. The configuration can work on IIS or Apache Web servers.
1.3. jaxcent provides a simple servlet container for independent deployment and operation.

2. concise and clear programming model

 

Generally, when developing Ajax applications, programmers have to write client-side JavaScript scripts to implement basic B/S communication, Dom control, State maintenance and updates, and other complex tasks. When using the jaxcent framework for Ajax development, everything is different. The client script is simplified to only one line: Introduce a. js file provided by the jaxcent framework. That's all. Of course, if your application does need to write more scripts to implement additional functions, it does not conflict with jaxcent.

 

The focus of subsequent development work has been completely transferred to the Java program on the server. Almost all Ajax-style functions originally implemented in the client script can be implemented on the server now. Designers on the front-end page no longer have to worry about whether they forget to add click events to a button or accidentally delete the event associations written by programmers. Programmers do not need to find the appropriate location for adding events in the HTML Tag of large movies.

In server development, jaxcent also provides convenient methods for using session and application context. When necessary, various content that requires dimension or synchronization status, it can also be automatically recorded in session entries.

3. Easy to implement and apply to projects


If you want to apply jaxcent to an existing or under-development project, you do not need to spend too much effort. Because the project does not need to be fully converted to the jaxcent framework, you only need to follow the jaxcent specifications for the newly added page or module. If you want to convert some of the existing code to the jaxcent framework, you only need to rewrite some of the Code to the server-side Java program. What the client needs to do is to delete the old Javascript script, in the future, the maintenance of the client can be completed independently by the art or designer.

 

----------------------
Iii. jaxcent impressions
----------------------
Take a simple Ajax application as an example. The function to be implemented is to synchronously display the current server time on the client page through Ajax technology.

 

  It is not complicated to implement this function using the standard Ajax method:

 

1. Start a timer on the page.
2. Create an XMLHTTPRequest object instance and set the callback function.
3. When a timer event occurs, send a request to the server through the XMLHttpRequest instance.
4. After the callback function receives the time data returned by the server, it updates the DOM element used for time display on the page (assuming it is a <p> label with ID = "lab_curtime ).

 

During standard model development, we need to do the following:

 

1. Compile the JS script involved in the above four steps on the design page, or write the script into a separate. js file and introduce it on the page.
2. Compile the interface program running on the server. Depending on the actual situation, it can be WebService, Servlet, JSP, ASP, PHP .......

 

The details that developers need to consider are as follows:


1. determine the format of the Request command sent from the client to the server, for example, set? Action = getcurtime.
2. Determine the data format in which the server sends the data back to the client, such as a simple string, JSON string, and XML segment that represents the current server time.
3. If the project is developed by a team, once the format is determined, it must be communicated with the development team members and expressed, and comply with the format conventions in other modules that may use the service.
4. Remind the client page or UI Designer to carefully process the JS script code inserted in the file when any page appearance changes may occur.

 

It is true that the standard development steps in this example are not as complex as considering the use of a tool library or even a framework.

   However, let's take a look at the situation if the jaxcent framework is used.


1. The designer designs the client page as usual
2. the designer adds a reference to the jaxcent JS Bridge on the page (typically, add in the head Tag: <SCRIPT type = "text/JavaScript" src = "/jaxcent. JS "> </SCRIPT>)
3. programmers write the server-side Java program. The main content is as follows:
A. The class inherits from jaxcent. jaxcentpage.
B. Declare a jaxcent. htmlpara variable HP and associate it with "lab_curtime ".
C. Obtain the current server time curtime.
D. Call hp. setinnerhtml (curtime ).
E. Create a thread and put C and D in the thread for scheduled execution.

 

Now, on our client page, the important <p> tag will continuously display the time text retrieved from the server.

--------------------------
Iv. Working Principles of the jaxcent framework
--------------------------

Currently, many Ajax Tool libraries or frameworks are being used by developers. The difference between the two lies in that the tool Library provides the basic function set for implementing Ajax-style programming, and the framework above this, then customizes a set of development specifications and programming models that must be followed at both ends of B/S.

 

The underlying working principle of the jaxcent framework is basically the same as that of framework products such as ASP. NET Ajax extensions. Use the XMLHTTPRequest object to transmit metadata and control commands between the browser and the server.

Based on the fact that the current Ajax framework standards are not uniform, jaxcent is positioned to provide a Lightweight Framework. Of course, lightweight is more important than mainstream Ajax framework products, it still takes a small amount of time to understand its structure.

 

As shown in the preceding example, the basic structure and workflow of an Ajax application based on the jaxcent framework are as follows:

 

Client page (JSP, HTML ...)<-->Javascript Bridge<-->Server jaxcent Servlet<-->Server Java program (class, Servlet, beans)

(The Javascript bridge and jaxcent servlet on the server are included in the jaxcent framework release package)

 

Through an intuitive understanding of the above flowchart and an analysis of the JS bridge code, we can summarize the actual working process of the jaxcent framework as follows:

 

1. In the JS bridge file introduced on the client page, an onload listener event is added to the window (adding rather than directly overwriting with "= ).
A. When the browser loads elements on the page, it triggers the mounted window. onload events.
In this event, the B. js bridge sends an initial request to the jaxcent servlet on the server. The sent data contains the URL of the current page.
C. servlet searches for the Java class associated with the page by querying the configuration file (described later). If yes, an instance of the class is created.
D. The servlet returns the element features (ID, Tag, type, etc.) that reload the event (such as onclick ).
E. js bridge finds the DOM Element Node corresponding to the feature and adds an event listener to it based on the response type.
* At This Point, jaxcent has initialized the page and entered the Ajax implementation period.

 

2. Communication between the client and the server
A. When a corresponding event occurs on the DOM node added with the relevant listener, The JS bridge will record and encode the status change and send it to the server servlet.
D. servlet transmits data to the response function of the corresponding event in the corresponding Java class according to the above method.

 

3. Communication from the server to the client
A. Like all current Ajax methods, the JS bridge will regularly send status queries to the server Servlet and discover the status to be sent back.
(This process can be controlled on the server to change the refresh interval, pause, or continue)
B. When the status of the return request indicates that a DOM node needs to be updated, the JS bridge looks for the target node and updates it accordingly (appearance, content, and status ).

 

4. Before closing the page, you can execute optional scanning tasks, such as suspending threads and destroying timers, to actively release system resources.

 

-------------------------
5. Dom operations of jaxcent
-------------------------
Based on the current version of jaxcent, the Framework provides almost all classes corresponding to Dom labels, and all Dom operations that can be implemented through JS scripts on the client, almost all Java classes can be implemented on the server.

 

In addition to common events such as mouse clicks, move-in, move-out, and Keyboard Events, the classes in the framework also encapsulate the extended functions of dragging and resizing.

For example, to implement the function of dragging a row in a table to another table, even developers who are very familiar with JS scripts will be bored when writing implementation code again, in addition to dragging, you also need to delete the old element and insert the new element after releasing the mouse.

 

With the support of the jaxcent framework, only 10 lines of code (two lines of key code) are required in the server program. All the complex Dom details are handled by related classes.

 

 

------------------------
Vi. jaxcent persistence support
------------------------
For most Ajax applications, the persistence support outside the database is of little significance, and the improvement of user experience is also very limited.
However, if a general persistence support is required for the client surface layer in an application, jaxcent's inherent advantages based on Java will become useful. Just think about it. It would be a headache to record all the client statuses in cookies or databases to organize the data (of course, jaxcent also provides a method to access cookies, if you really need to use it), then think about serialization of three words, the application will feel a lot easier.

 

 

--------------------------
7. Deployment and configuration of jaxcent
--------------------------
... Not written yet
----------------------
8. jaxcent Class Structure
----------------------
... Not written yet
--------------------------
9. jaxcent Integrated Application Example
--------------------------
... Not written yet

 

---------------------
10. Official jaxcent website
---------------------

Http://www.jaxcent.com/


 

Related Article

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.