Programming Assignment 10 (optional)
Web Application Development using Eclipse

Due on Thursday May 1 before midnight


Description

This project is optional. If you don't do this project you will get 100 points, but if you complete this project successfully you will get up to 150 points (2.5 extra points in your final score).

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 4 using JavaServer Faces (JSF).

This project must be done individually. No copying is permitted. Note: We will use a system for detecting software plagiarism, called Moss, which is an automatic system for determining the similarity of programs. That is, your program will be compared with the programs of the other students in class as well as with the programs submitted in previous years.

Note that, if you use a Search Engine to find similar programs on the web, we will find these programs too. So don't do it because you will get caught and you will get an F in the course (this is cheating). Don't look for code to use for your project on the web or from other students (current or past). Don't try to hire a freelancer to do the coding for you. Just do your project alone using the help given in this project description and from your instructor only.

Platform

You will do this project on your own PC/laptop using Eclipse. Directions:

Install Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/. Choose "Eclipse IDE for Java EE Developers", download the latest version: Kepler and unzip. It will create a folder named "eclipse". Start Eclipse by going to the "eclipse" folder and by double-clicking on eclipse.exe.

Download and unzip Apache Tomcat 7.0 (the Core). Start Eclipse and click on Window → Show View → Other... → Servers to get the Servers window. On the Servers window click to define a new server then select Apache/Tomcat v7.0. Choose your apache-tomcat folder and push "finish". You should now see "Tomcat v7.0 Server at localhost" listed under the Servers tab at the bottom.

To install JSF, download the Oracle Mojarra JavaServer Faces from http://javaserverfaces.java.net/. The current stable version is JavaServer Faces RI 2.2 (not 1.2). Download the JavaServer Faces javax.faces-2.2.1.jar the JSTL tag libraries jstl-1.2.jar from here. On Eclipse, do: Preferences → Java/Build Path/User Libraries → New.... Use the user library name: JSF (make it a System library) and add the External JARs: javax.faces-2.2.1.jar and jstl-1.2.jar. Make the Web Page editor to be your default as follows: 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: project10. In the Configuration section, select the JavaServer Faces v2.2 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. Create a buy.jsp file by right-click and select New JSP File... with File name: buy.jsp, then Use JSP Template: New JavaServer Faces (JSF) Page (html) and push Finish. If you don't see the GUI editor, right-click on the file text and select Open With → Web Page Editor. If you don't see the palette, right-click on the GUI canvas and select Show → Palette. You can move the palette to the right column by dragging and dropping. Use the JSF HTML sub-menu.

Documentation

Use them as a reference only:

Project Requirements

You need to re-implement the web application described in Project 4 (the e-commerce web application using the eBay Commerce Network API) using Java Server Faces on Eclipse, instead of PHP. You should not use any PHP or JavaScript code.

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 java.net.URL class. To URL-encode the query string, use the java.net.URLEncoder class. For example, this calls the ISBN DB and prints the result.

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:form>
   <h:panelGrid border="1" columns="1">
      <h:selectOneListbox value="#{shop.buyItem}">
         <f:selectItems value="#{shop.lastSearchItems}"/>
      </h:selectOneListbox>
      <h:commandButton value="buy" action="next"></h:commandButton>
   </h:panelGrid>
</h:form>
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 minPrice and name) and value is the product Id. 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 Id of the selected item to buy
   String removeItem = "";      // holds the Id 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 id ) {...}

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

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

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

   ...
}
Note that #{shop.lastSearchItems} becomes a call to the bean getter method (getLastSearchItems). 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 using the following form.

Submit Project #10:

Last modified: 04/15/14 by Leonidas Fegaras