In this chapter, you will see three frameworks that all have a common goal: to make the task of developing Ajax-enabled web sites easier and quicker. They all try to abstract the details concerning the underlying communications between the server and the client, leaving the developer free to concentrate on the more interesting aspects, such as implementing the classes that actually take care of the business logic peculiar to an application.
This chapter focuses on the following three frameworks, among the many available:
JPSpan: JPSpan integrates with PHP, a robust and open source server-side language.
DWR: DWR allows calls to Java classes on the server.
Ajax.NET: Ajax.NET enables communication with server-side classes built with any .NET language.
The examples for each framework follow a common pattern: each demonstrates how to create a business object and call its methods asynchronously from an HTML client.
The term business object is given to a class that reflects a real-world entity and has the methods and properties necessary to support working with it from within an application. An example would be a Video class used in a video store's booking system. The Video class might have properties such as title and dailyRentalCost, and methods such as isOverdue().
The business object in our examples will represent a customer, a common class in many applications. In a real-life scenario, the Customer class could contain many properties, such as the customer's name, address, and how long he or she had been a client, as well as methods such as getOutstandingOrders().
To make the examples more manageable and allow them to focus on the use of the frameworks, the Customer class used in the examples is much simpler. It has only one method, getAddressFromEmail(), which returns the customer's address given his or her e-mail address as a parameter.
In a well-built application, the business classes, representing real-world entities, are separate from the data classes, which deal with persisting the details to a permanent storage facility, such as a relational database. To keep the examples straightforward, the Customer class itself will handle retrieving information from the database.