Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Ajax In Action (2006).pdf
Скачиваний:
63
Добавлен:
17.08.2013
Размер:
8.36 Mб
Скачать

The Ajax portal architecture using Java

427

 

 

Figure 11.3 A9.com’s portal showing the search results with the Book Results column

configuration-management tools by having the user click on objects in the window instead of going to another web page to configure the setup. The user can dynamically resize and position the elements on the screen, thus customizing his portal to fit his needs exactly.

Now that we’ve seen some of the advantages of an Ajax portal, let’s look at the architecture of the portal we will be building.

11.2 The Ajax portal architecture using Java

To provide a highly customizable Ajax portal for multiple users, we need clientside code, server-side code, and a database. The client side handles the users’ interactions with the windows, such as dragging, dropping, and sending data back to the server with Ajax. The server, in return, handles our users’ sessions, data transfer back to the client, and interaction with the database. The database holds our users’ logins and passwords in one table, and a second table holds the portal window metadata, such as the position, size, and content.

This project has a lot of steps since it contains dynamic results. To get this project started, let’s look at how the project flows (figure 11.4).

428CHAPTER 11

The enhanced Ajax web portal

 

Server

 

 

Grab user

Save user

Verify

preferences

preferences

 

 

login

 

 

 

Error

 

Login

 

 

 

Build

Send users

 

windows

changes

Browser

Figure 11.4 Ajax portal flow. Users log in to the portal and manage their windows. Changes are saved automatically in the background while they work.

The basic idea of the rich user interface portal that uses Ajax to interact with the server sounds difficult, but you will be amazed at how simple it is to implement the project. The portal architecture illustrated in figure 11.4 contains two major portions: the initial login and the dynamic interaction with the windows. Thus, we can break our processes into two different sections and adapt the Ajax functionality to meet those needs. The first operation validates a user’s credentials against a database, and the second operation interacts with DHTML elements and returns values to our client.

In this chapter, we use a DHTML library to handle a lot of the client-side code. The DHTML library allows us to develop customizable windows that use IFrames to display content. The DHTML windows created by this library can be positioned anywhere on the page since the library supports dragging functionality. Another feature the library supports is resizing of the windows, so we can make the window any size we want. The DHTML library frees us from dwelling on the cross-browser problems that we might encounter with these actions. Instead we can focus on adding the Ajax technology into this library to make a dynamic script even more powerful by integrating it with the server.

The implementation that we’ll present here uses Java on the server side, simply to provide a little variety from the previous two chapters, which used .NET languages. We’ve kept the implementation fairly simple. Because Ajax can work equally well against any server-side technology, we won’t concentrate on the server-side details. The full source code for the server tier is available as part of the download for this book. Let’s start off by introducing the Ajax login.