ch7.accountLogin
Class ControllerHelper

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

public class ControllerHelper
extends HelperBaseCh6

The login page displays as the first page.

The user must enter a valid account number before proceeding.


Nested Class Summary
 
Nested classes/interfaces inherited from class shared.HelperBaseCh4
HelperBaseCh4.SessionData
 
Field Summary
protected  RequestDataAccount data
          The default page forces the user to enter a valid login number.
 
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)
          Call the base class constructor to store the request and response.
 
Method Summary
 java.lang.String confirmMethod()
          The method to call when the confirm button is clicked.
 void copyFromSession(java.lang.Object sessionHelper)
          The implementation of the abstract method from the helper base.
protected  void doGet()
          GET is considered a new request, so the old data is not read and the JSP is always for the edit page.
protected  void doPost()
          POST is considered a continuation of a previous request, so read the old data from the session and calculate the next page based on the button.
 java.lang.String editMethod()
          The method to call when the edit button is clicked.
 java.lang.Object getData()
          An accessor that allows the JSPs to retrieve the bean from the helper.
 java.lang.String getMethod()
          This is the default method.
static void initHibernate(boolean create)
          The properties are in the hibernate.cfg.xml file.
 java.lang.String jspLocation(java.lang.String page)
          Encapsulates the location of the JSPs.
 java.lang.String loginMethod()
          The method to call when the loginButton button is clicked.
 java.lang.String newUserMethod()
          The method to call when the newUser button is clicked.
 java.lang.String processMethod()
          The method to call when the process button is clicked.
 
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, writeError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected RequestDataAccount data
The default page forces the user to enter a valid login number.

If the login number is in the database, then the data is retrieved and set as the data for the helper.

Constructor Detail

ControllerHelper

public ControllerHelper(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
Call the base class constructor to store the request and response.

Parameters:
request - Request information encapsulated in a Java object
response - Response information encapsulated in a Java object
Method Detail

initHibernate

public static void initHibernate(boolean create)
The properties are in the hibernate.cfg.xml file. Conditionally create the table and initialise hibernate.

Parameters:
create - true means create the table, false means do not create

getData

public java.lang.Object getData()
An accessor that allows the JSPs to retrieve the bean from the helper.

Returns:
The bean that contains the data from the request.

copyFromSession

public void copyFromSession(java.lang.Object sessionHelper)
The implementation of the abstract method from the helper base.

The method copies data from the old helper that is still in the session to the current helper. It is necessary to copy the checked and selected maps as well as the data; otherwise, it will not be possible to inialise the advanced form elements with the old data.

Specified by:
copyFromSession in class HelperBaseCh4
Parameters:
sessionHelper - The old helper that is still in the session.

jspLocation

public java.lang.String jspLocation(java.lang.String page)
Encapsulates the location of the JSPs.

Parameters:
page - The file name of the JSP.
Returns:
The full path to the JSP.

getMethod

public java.lang.String getMethod()
This is the default method. There is no button associated with it.

Returns:
The address of the JSP.

loginMethod

public java.lang.String loginMethod()
The method to call when the loginButton button is clicked.

Fill the bean from the request. Call setErrors to generate the error messages for the data. There is only one field that is entered in the login form, so call isValidProperty to test if that field is valid. If isValid were called, all of the validations would be tested, even for data the has not been entered yet.

If the data is valid, then try to retrieve the data for that account from the database. If there is a bean, then set it as the current data. Clear the error map, so that errors do not appear on the edit page, when it is displayed for the first time.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

newUserMethod

public java.lang.String newUserMethod()
The method to call when the newUser button is clicked.

Create a new bean in order to delete the old values in the session.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

editMethod

public java.lang.String editMethod()
The method to call when the edit button is clicked.

The method does nothing else at this time than indicate the address of the page.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

confirmMethod

public java.lang.String confirmMethod()
The method to call when the confirm button is clicked.

Implement required validation by calling isValid. If the data is valid, then proceed to the confirm page; otherwise, return to the edit page.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

processMethod

public java.lang.String processMethod()
The method to call when the process button is clicked.

Test if the data is still valid; if it isn't, then the session has expired. If the data is valid, then save it to the database.

Retrieve all the data from the database and add it to the request so that the JSPs can access it.

The method is adorned with a ButtonMethod annotation that associates the name of a button with the method.

Returns:
The address for the JSP.

doGet

protected void doGet()
              throws javax.servlet.ServletException,
                     java.io.IOException
GET is considered a new request, so the old data is not read and the JSP is always for the edit page.
  1. Add the helper to the session but ignore the data from the old helper in the session
  2. Always call the default method.
  3. Forward the request and response to the next address.

Overrides:
doGet in class HelperBaseCh4
Throws:
javax.servlet.ServletException
java.io.IOException

doPost

protected void doPost()
               throws javax.servlet.ServletException,
                      java.io.IOException
POST is considered a continuation of a previous request, so read the old data from the session and calculate the next page based on the button.
  1. Add the helper to the session and copy the old helper data into the current helper. This eliminates the need for hidden fields.
  2. Call the appropriate method for the clicked button. This is done from a method in the helper base that loops throuh all the button methods, looking for the one for the clicked button. This eliminates the need for the nested if-else block.
  3. Forward the request and response to the next address.

Overrides:
doPost in class HelperBaseCh4
Throws:
javax.servlet.ServletException
java.io.IOException