Programming Assignment 4
Web Application Development using Eclipse

Due on Tuesday February 28 before midnight


This project must be done individually. No copying is permitted. The goal of this project is to learn server-side web application development using Eclipse. More specifically, you will develop the same shopping web application from Project 3 using JavaServer Faces (JSF).


Use them as a reference only:

Project Requirements

You need to re-implement the web application described in Project 3 using Java Server Faces on Eclipse, instead of PHP. You should not use any PHP or JavaScript code.

If you haven't installed JSF, download the Oracle Mojarra JavaServer Faces from The current stable version is JavaServer Faces RI 2.1 (not 1.2). Download the JavaServer Faces javax.faces-2.1.6.jar and the JSTL tag libraries jstl-api-1.2.jar and jstl-impl-1.2.jar. On Eclipse, do: Window → Preferences → Java/Build Path/User Libraries → New.... Use the user library name: JSF (make it a System library) and add the JARs: javax.faces-2.1.6.jar, jstl-api-1.2.jar, jstl-impl-1.2.jar. Make the Web Page editor to be your default as follows: Window → Preferences → General /Editors/File Associations, select *.jsp, and then make Web Page Editor the default.

To create a JavaServer Faces project on Eclipse do: Select File → New → Project.., then select Web → Dynamic Web Project and set the name for the project: project4. In the configuration section, select the JavaServer Faces v2.0 Project. On the Web Module page, check on Generate web.xml deployment descriptor. On the JSF Capabilities page, add the JSF library and click Finish.

You may use the Java DOM API to access XML data based on DOM. Here is a DOM example. To call a web service, use the class. To URL-encode the query string, use the class. For example, this calls the ISBN DB and prints the result. Note that, to get the results from the Google search API for shopping in XML format you need to add &alt=atom to the URL.

Detailed Directions

You need to write a buy.jsp JSF file that uses two listboxes to hold the last search results and your shopping basket. It must also have a form to search for more items, a form to clear the basket, and a place to print the total price. For example, your search results can be displayed in a listbox where you may choose one to buy by pressing a button. Here is how to do this in JSF:

   <h:panelGrid border="1" columns="1">
      <h:selectOneListbox value="#{shop.buyItem}">
         <f:selectItems value="#{shop.lastSearchItems}"/>
      <h:commandButton value="buy" action="next"></h:commandButton>
The shop.lastSearchItems getter method must return a key/value map (from string to string), where the key is the description (eg, a concat of price and title) and value is the googleId. You may use a similar form for the shopping basket, in which the button deletes the selected item. You need to create two session beans: one ShopItem to hold one item and Shop that contains your session data:
public class Shop {
   // the shopping basket
   Map<String,ShopItem> basket = new HashMap<String,ShopItem>();
   // the results of the last search
   Map<String,ShopItem> lastSearch = new HashMap<String,ShopItem>();
   String queryString = "";     // holds the search query
   String buyItem = "";         // holds the googleId of the selected item to buy
   String removeItem = "";      // holds the googleId of the selected item to remove from basket
   double totalPrice = 0.0;     // holds the total price of the basket items

   // move this item from search list to the basket
   public void buy ( String googleId ) {...}

   // set the search list using the Google shopping API
   public void search ( String queryString ) {...}

   // create a map from search item descriptions (keys) to googleIds (values)
   public Map<String,String> getLastSearchItems () {...}

   // create a map from basket item descriptions (keys) to googleIds (values)
   public Map<String,String> getBasketItems () {...}

These are just suggestions; feel free to change the code.

What to Submit

You need to submit your buy.jsp file and your Java files in the src directory using the following form.

Submit Project #4:

Last modified: 02/14/12 by Leonidas Fegaras