Ajax Programming in BEA WebLogic Portal 8.1, Part 1by John Margaglione AbstractPortal applications do an excellent job of surfacing information from multiple sources and providing application services to the portlets that comprise the portal Web application. To the user, the portlet applications are independent entities, similar to windowed applications on a desktop. Extending that analogy, what if taking an action in one windowed application caused the content in all other applications to be refreshed? That is the current state of most portals. Moving through a page flow in one portlet causes the entire Web page to be refreshed, including all other portlets on that page. To combat this sometimes undesirable behavior, Web developers have employed what is referred to as Ajax-style programming. Ajax, or Asynchronous Java and XML, is a collection of technologies including XHTML, CSS, JavaScript, DOM, and the A Brief Introduction to AjaxConsider a Web application that draws street maps based on some user criteria such as the street address, city, and state. This type of application has been around for years with little change in the user interface. The user enters an address and clicks a button, and a map of the surrounding area is displayed in the center of the page. More often than not users need to zoom in and out to show more of the surrounding area, or they need to nudge the map a bit to the left or right to see some major street or landmark that will help them navigate. Try this scenario using maps.yahoo.com or mapquest.com. Go on, try it! Try this address: 100 East Wacker Drive Eventually you are greeted with a map of downtown Chicago, centered on Wacker and Michigan. To the right you'll see a series of zoom levels you can choose. Choose to zoom in one level. What happens? The entire page refreshes, taking quite some time to do so. Now, what happens when you nudge the map left or right? You inevitably end up refreshing the entire page, with the entire map needing to be downloaded again. The page size is generally 75 to 100k, and the average turnaround time is about 3 to 10 seconds, depending on your Internet connection. Now try the same thing using Google Maps, a site that uses Ajax techniques to the fullest. Type in the address and click Search. The page loads in its entirety. Now zoom in a level. Notice that the page contents outside of the map did not refresh. This is what happened in the background:
Notice that there are no arrows surrounding the map indicating north, south, east, and west. How does the user interact with the map? You simply drag the map around as if it were in a scrolled window. Try clicking the center of the map and dragging the map to the left. Notice how responsive the map is when it is dragged! Here is what's happening in the background:
Here's what the use of Ajax achieves
That should be an impressive demonstration of Ajax-style user interfaces. (If, after using Google Maps for a few days, you aren't convinced that the competition is annoying and very 1990s, you need not read the rest of this article.) For a more thorough introduction to Ajax, please read An Introduction to Ajax (dev2dev, August 2005). Portal Issues that Ajax RemediesConsider potential customers who are heavy users of Java applets and want to create portals using their existing assets. It is simple enough to wrap existing applets and other page flows into portlet containers, but consider what issues will emerge as the portal testing begins. For example, an action in one portlet causes the refresh and subsequent reload and reinitialization of all other applet-based portlets on the page. If the applets in question have backend connections, as would streaming portlets, then the reinitialization of the portlet causes the server to drop the existing connection and forces the applet to reconnect, which is not only a strain on the server but also presents users of the portal with several seconds of "dead time" during which the applet-based portlets must remain grayed out as they finish their initialization. This is obviously a potential showstopper. Telling customers to rewrite all their applets as JSP-based applications is not a useful response, especially for customers that have invested significant resources into the existing assets. Besides, a portal is supposed to help customers surface their existing applications, not force a rewrite of their entire system. What is needed is a way for an individual portlet to take actions or get new data without causing a page refresh. While this obviously has some downsides I will discuss later in this article, it is necessary in this case to avoid page refreshes simply as a barrier to entry for using the portal. Side note: One possible solution to this problem is iframes, or inline frames, a browser-based mechanism that makes an area of the screen an independent entity that does not refresh when the page is reloaded. Using techniques similar to those used in Ajax programming, it is possible to make server calls using XML-RPC to get data and load it into a DOM document. An article on Apple's developer Web site summarizes the pros and cons of this method very well. I am sure there are great arguments on both sides for why iframes and Ajax are both better, but Ajax has caught on and iframes have not. Therefore, this article deals with Ajax and not iframes. Use CasesAjax technologies are useful when any of the following conditions are present:
|
Article Tools Related Products Check out the products mentioned in this article:Related Technologies Related Articles Bookmark Article
|