| By Anil Sharma | Article Rating: |
|
| May 16, 2007 07:30 PM EDT | Reads: |
5,639 |
This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs for the special pre-order price, click here for more information. Aimed at everyone from enterprise developers to self-taught scripters, Real-World AJAX: Secrets of the Masters is the perfect book for anyone who wants to start developing AJAX applications.
Controller
In the previous section we discussed a set of abstractions that are sub-classes of the component. A component class abstracts some behavior and to implement that, it might add a set of event listeners to its elements. Those event handlers are encapsulated in the component class and serves as its controllers. But in a bigger scheme of things, they are fully contained in the component class and can be considered a part of the View.
Besides component-specific listeners, there is a set of application-specific event listeners that respond to user inputs or timer events. These are called controllers. An event handler is a trigger point for some behavior implemented by the rest of the controller. This behavior can commonly be categorized as follows.
- Controllers that simply change the state of the view such as color, enabled/disabled, hide/visible, and font based on some application logic.
- Controllers that trigger re-rendering of the UI or its part due to some data change or navigation.
- Controllers that execute some business logic or do computation. Here you need to worry about the security issues based on other parameters such as if the application is running over an intranet or Internet. Based on such parameters, the business logic can be executed in the browser space or delegated to the server. In almost all cases, if some other data look-up is needed, then it's recommended that the task be delegated to a back-end service through the controller servlet.
- Controllers that fetch data from the back-end server, update the client model, and send a trigger to the View for re-rendering data.
- Timer controllers that do something periodically. For example, a timer can periodically check for the availability of new updates on the server.
MVC Interaction
We've described the Model, View, and Controller components of the MVC pattern. Now let's consider a typical sequence of operations on the client side to understand the interactions among them better.
- As a result of access to a URL by the user, the browser downloads a page and triggers the execution of certain controller code due to its "onload" event.
- In the first step, the controller retrieves the HTML template from the server using an AJAX call.
- Next the controller retrieves data from the server using an AJAX call and inserts it into the cache.
- Then the controller instantiates one or more components, creating an association between the components and HTML elements.
- To populate the data, the controller invokes a "setValue" call on one or more components.
- Lastly, the controller adds application-specific event handlers to the elements.
This content is reprinted from Real-World AJAX: Secrets of the Masters published by SYS-CON Books. To order the entire book now along with companion DVDs, click here to order.
Published May 16, 2007 Reads 5,639
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Anil Sharma
Anil Sharma is a founder of Vertex Logic and architect of its AjaxFace product. He is working with Vertex Logic's customers and helping them deploy WEB 2.0 applications built using AjaxFace. These applications are in the areas of online printing, community WEB sites and social networking. He is driving future products of Vertex Logic. Prior to Vertex Logic, he was CTO and founder of Softrock Systems and Component Plus. There he built a model driven application platform using J2EE. His primary interests include user interface infrastructures and model driven applications. He is one of the contributors of the book "Real World AJAX - Secrets of the Master".
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Practical Approaches for Optimizing Website Performance
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- WPF Controls by DevExpress
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX
































