|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
Cover Story AJAXifying the WebDataWindow
How to apply an AJAX technique to improve the WebDataWindow experience
Sep. 19, 2006 06:30 PM
When we talk about AJAX and its huge impact on Web development, one important thing to mention is that it's not a ready-to-ship component that you just plug into your app and now you're Web 2.0. In fact, what AJAX can do for you is to provide a simple, yet powerful way to make transparent server requests; but nothing more than that. The important point with AJAX is what to do with it. In other words, how do we use it to improve the user experience?
Server-side Actions WebDataWindow Components This control is divided in two components: The WebDataWindow server component and the WebDataWindow client component. The former runs on the Web server and talks directly to the persistent layer. It basically gets data, applies actions (server-side actions), and then generates the client component. The client component runs on the client (Web browser). It interacts with the user, triggers events, and then performs server-side actions. These two components are always communicating with each other. Each communication requires a server interaction. Then, to build our solution, we have to understand very clearly the communication standard between these components. WebDataWindow Server Component WebDataWindow Client Component Therefore, when a server action is triggered, the client component builds the context and submits this form to be processed by the server component.This is how the client component talks with the server component. AJAX Solution A typical AJAX interaction is made up of a server request followed by client-side processing of the XML returned by a callback function. In our model, the first part (the server request) represents the client component communicating with the server component. The second part (the XML building and client-side processing) represents the server component communicating with the client component. AJAX Request - Client Component Communicating To do this, we have to intercept the form submission by implementing the client-side OnSubmit event. In this event we must gather all the data in the submission form, trigger an AJAX request, and then prevent the original submit from occurring (see Listing 1). The code for the getFormValues and loadXMLDoc functions is provided in Listing 2. XML Building - Server Component Communication In the standard communication model, we simply generate the client component code and then flush it to the Web browser. But, in the AJAX model, one step will be required between the generation and the content transmission. Instead of sending the code generated, an XML string holding the client component will be built. On most XML-oriented applications, the XML content's nature is pure data. It will normally hold database data. But, in the WebDataWindow approach, bringing in just the data isn't enough to cover the whole WebDataWindow component's communication cycle (See Figure 1). To have a full working client component, it's necessary to bring down all its generated code. Remember that the DataWindow component is more than just a simple data placeholder. It's a data and presentation manager that requires much more than just the data itself. It handles complex presentation logics, like grouping, or expression conditioned text formatting. It also handles data status like DataModified! and NewModified!. Hence, the XML must hold the full client component code. To build that XML, the client component code must be divided into logical parts. The JavaScript part, the HTML part, and the CSS part will be put into separated tags in the XML. So it's necessary to extract these parts from the generated code. This division is necessary because each type of code (HTML, CSS, and JavaScript) requires a particular treatment in the client-side processing. Listing 3 is sample code that extracts those parts written in VBScript language. The resulting XML will look like Listing 4. To see a full sample XML, see Listing 5. Other custom tags can be added into the XML to send extra information about the action being performed, such as error messages, application messages, warnings, and database data. The XML string is now ready to be sent back to the client. XML Client-Side Processing - Server Component Communication First we have to inject the HTML part. This injection is performed by changing the innerHTML attribute of the tag that currently holds the client component. This includes identifying this tag (see Listing 6). Then we concatenate the CSS part to this same innerHTML attribute. It's important to do it in this order. First the HTML part is set then the CSS part is added to the innerHTML attribute. This guarantees that the styles are correctly applied to the HTML part. Finally, the JavaScript part must be executed. This will create the client component with full functionality. To execute this code, the eval JavaScript built-in function will be used (see Listing 6). This function takes as an argument a string variable holding JavaScript code, parses this code, and runs it. This finishes the whole communication cycle between the client component and server component, using AJAX as the method of communication. Conclusion Many others solutions and improvements can be implemented for performance's sake. Some special cases may use different approaches. For instance, retrieving DropDownDataWindows dynamically depending on columns values. Nevertheless, it's always a matter of identifying the necessity of improvement, study the situation, and apply AJAX. Resources
Reader Feedback: Page 1 of 1
Your Feedback
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||