ch7.catalog
Class ControllerHelper

java.lang.Object
  extended by shared.HelperBaseCh4
      extended by shared.HelperBaseCh5
          extended by shared.HelperBaseCh6
              extended by ch7.catalog.ControllerHelper
Direct Known Subclasses:
ControllerHelper

public class ControllerHelper
extends HelperBaseCh6

The application uses two beans: catalogItem and ShoppingCart. There will be an accessor for each of these beans, so that each can be retrieved from a JSP. The copyFromSession method will need to retrieve both beans from the session. There are buttons for all the actions that can be performed on the cart.

The catalog items must be created before this application is run. Call the CreateCatalog servlet to create the database of catalog items.


Nested Class Summary
 
Nested classes/interfaces inherited from class shared.HelperBaseCh4
HelperBaseCh4.SessionData
 
Field Summary
protected  ShoppingCart<CatalogItem> cart
          The bean for the shopping cart.
protected  CatalogItem item
          The bean that encapsulates a catalog item.
 
Fields inherited from class shared.HelperBaseCh6
checked, selected
 
Fields inherited from class shared.HelperBaseCh4
logger, request, response
 
Constructor Summary
ControllerHelper(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          The only constructor for this class has parameters for the request and response objects.
 
Method Summary
 void copyFromSession(java.lang.Object sessionHelper)
          Most of the details for retrieving data from the session are implemented in the helper base class.
protected  void doGet()
          This method will be called by the controller to finish processing the request.
protected  void doPost()
          This method will be called by the controller to finish processing the request.
 java.lang.Object getCart()
          Accessor that returns the shopping cart bean.
 java.lang.Object getItem()
          Accessor that returns the catalog item bean.
static void initHibernate(boolean create)
          Uses properties to set the configuration parameters for Hibernate.
 java.lang.String jspLocation(java.lang.String page)
          Generates the full path to a JSP.
 java.lang.String methodAddCart()
          The method that preforms the actions associated with the login button.
 java.lang.String methodDefault()
          The method that preforms the default actions when no button is clicked.
 java.lang.String methodEmptyCart()
          The method that preforms the actions associated with the empty cart button.
 java.lang.String methodProcessCart()
          The method that preforms the actions associated with the process cart button.e database and used to fill the entry form.
 java.lang.String methodViewCart()
          The method that preforms the actions associated with the view cart button.
 java.lang.String methodViewItem()
          The method that preforms the actions associated with the view item button.
 
Methods inherited from class shared.HelperBaseCh6
addChecked, addChoice, addSelected, clearMaps, clearProperty, getChecked, getSelected, invokeGetter, setCheckedAndSelected, setCheckedAndSelected
 
Methods inherited from class shared.HelperBaseCh5
getErrors, isValid, isValidProperty, setErrors
 
Methods inherited from class shared.HelperBaseCh4
addHelperToSession, addHelperToSession, executeButtonMethod, executeButtonMethod, fillBeanFromRequest, invokeButtonMethod, populateThrow, writeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

item

protected CatalogItem item
The bean that encapsulates a catalog item. It will hold the data for the catalog item that the user has selected.


cart

protected ShoppingCart<CatalogItem> cart
The bean for the shopping cart. It will contain all the catalog items that the user has selected.

Constructor Detail

ControllerHelper

public ControllerHelper(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
The only constructor for this class has parameters for the request and response objects. These objects will be stored in member variables.

Parameters:
request - The object that encapsulates the request information that is needed to communicate with the browser.
response - The object that encapsulates the response information that is needed to communicate with the browser.
Method Detail

initHibernate

public static void initHibernate(boolean create)
Uses properties to set the configuration parameters for Hibernate. Three properties must be changed: connection string, username and password.

Parameters:
create - If there is an initilization parameter named 'create' in the web.xml file, then its value will be sent to this method. If it is true, then it means that the table for the bean should be created in the database.

getItem

public java.lang.Object getItem()
Accessor that returns the catalog item bean. This accessor is required so that the bean can be retrieved from a JSP, using the expression language. Only public accessors and mutators can be accessed using the expression language.

Returns:
The bean for this application.

getCart

public java.lang.Object getCart()
Accessor that returns the shopping cart bean. This accessor is required so that the bean can be retrieved from a JSP, using the expression language. Only public accessors and mutators can be accessed using the expression language.

Returns:
The bean for this application.

copyFromSession

public void copyFromSession(java.lang.Object sessionHelper)
Most of the details for retrieving data from the session are implemented in the helper base class. The specific details concerning the actual data must be implemented in the controller helper, since each application can have different data. The specific details are implemented in this method; it is the implementation of an abstract method in the helper base class.

Specified by:
copyFromSession in class HelperBaseCh4
Parameters:
sessionHelper - The object that represents the controller helper that was added to the session in the previous request.

During each request, the controller helper is placed in the session. Before that happens, the controller helper from the previous request can be retrieved from the session. This object is retrieved in the helper base class and sent to the implementation of this abstract method.

There are two beans in this application, so both need to be copied from the session into the current class.


jspLocation

public java.lang.String jspLocation(java.lang.String page)
Generates the full path to a JSP.

Parameters:
page - The name of the JSP. This will be appended to the path of the directory that contains the JSPs. Using this method forces all the JSPs to be in the same directory.
Returns:
The string that represents the complete path to the JSP. This path must be relative to the directory where the servlet is mapped or must begin with a /, which represents the root of the web application.

methodDefault

public java.lang.String methodDefault()
The method that preforms the default actions when no button is clicked.

Returns:
The address of the JSP that will complete the request.

methodAddCart

public java.lang.String methodAddCart()
The method that preforms the actions associated with the login button. After logging in, the user's data will be retrieved from the database and used to fill the entry form.

Returns:
The address of the JSP that will complete the request.

methodEmptyCart

public java.lang.String methodEmptyCart()
The method that preforms the actions associated with the empty cart button.

Returns:
The address of the JSP that will complete the request.

methodViewItem

public java.lang.String methodViewItem()
The method that preforms the actions associated with the view item button.

Returns:
The address of the JSP that will complete the request.

methodViewCart

public java.lang.String methodViewCart()
The method that preforms the actions associated with the view cart button.

Returns:
The address of the JSP that will complete the request.

methodProcessCart

public java.lang.String methodProcessCart()
The method that preforms the actions associated with the process cart button.e database and used to fill the entry form.

Returns:
The address of the JSP that will complete the request.

doGet

protected void doGet()
              throws java.io.IOException,
                     javax.servlet.ServletException
This method will be called by the controller to finish processing the request. The controller is the servlet, so its doGet method will be called by the servlet engine. The controller will then call this doGet method.

GET requests will be treated as first requests to the application. Previous data will not be retrieved from the session and the edit page will always be displayed.

Overrides:
doGet in class HelperBaseCh4
Throws:
javax.servlet.ServletException - A servlet exception is a severe error and means that processing cannot continue.
java.io.IOException - An IO exception is a severe error and means that processing cannot continue.

doPost

protected void doPost()
               throws javax.servlet.ServletException,
                      java.io.IOException
This method will be called by the controller to finish processing the request. The controller is the servlet, so its doPost method will be called by the servlet engine. The controller will then call this doPost method.

POST requests will implement the controller logic that has been in all previous controllers.

Overrides:
doPost in class HelperBaseCh4
Throws:
javax.servlet.ServletException - A servlet exception is a severe error and means that processing cannot continue.
java.io.IOException - An IO exception is a severe error and means that processing cannot continue.