Although Books Galore! is simple in structure and application, the fundamentals used illustrate what can be done, even with a simple CGI operation on a text-based data set (see fig. 22.1).
Figure 22.1 : The opening page of Books Galore! is a
simple form that enables the user to choose which types of books
to browse. The results of the form are used to parse a database
and retrieve the product information.
The Books Galore! ordering demo is found at http://weber.u.washington.edu/ ~davidnf/java/bookstore.html. As you try out the system, don't worry about the bill: it's only a demo, so no one is waiting on the other end of the line to take your money.
"Initially, I was just looking at what could be done,"
Nagy-Farkas says. He looked at a lot of other Web sites to see
found really wasn't that practical. There were a lot of calculators
and stuff like that," but nothing that really indicated some
of the more powerful client-side functions that are useful when
dealing with data and a server.
David Nagy-Farkas's home page for Live Web Designs is found at http://weber.u.washington.edu/~davidnf/java/bookstore.html. The page includes examples of frames and Java applets.
The product ordering system began as a simple project to keep a running total of items as a user selected or deselected items. "It was really pretty simple," Nagy-Farkas says. "I just worked with 'on-event' handlers. Anytime any field was changed that could affect the price, I recalculated the total."
Because he was still working with relatively undocumented beta releases from Netscape, his progress was hindered by a lack of information. "The running-total program was about as far as it could go with the state of the online documentation."
Figure 22.2 : This page is used for choosing which books to order and how many. Note the form fields at the bottom of the screen that contain the running totals. These are updated as soon as one of the fields above it is changed or clicked.
"I only write a few lines at a time and then test them to make sure they work," he says. "When something goes wrong, it's a lot easier to track down where and what it is." The other result is robust code that the programmer knows works "every step of the way."
Listing 22.1 bookorder.html An HTML Page
"The toughest part is parsing the database, especially if it's a large one," he says. Books Galore! is designed to take the extraneous parsing load off the server. Current CGI online ordering systems require parsing the database after each selection and then generating a new total with a new page to display it. "If you have a big list of items, redrawing is a pain."
Figure 22.3 : After the user submits an order, another CGI script generates the final invoice with information from the order screen, including a form at the bottom for entering name, address, and payment information.
"It's really a nightmare keeping track of how things are typed," Nagy-Farkas says. A variable acts according to how it's being used-which affords a lot of flexibility, but also causes a lot of confusion, in passing parameters. "It takes a little time to figure out whether that integer you just passed into a function thinks it's an integer or a string."
When Nagy-Farkas posted the first running total calculation application, no one seemed to be too interested. After adding the CGI script and the book order wrapping, "Feedback has been very positive" in spite of the fact the basic functionality of the page hasn't changed much-it still keeps a running total based on the most current user input.
"A lot of people have been asking for a 'vanilla' version of the Books Galore! program," Nagy-Farkas says. "It's really pretty portable right now."