ch6.complexInit
Class ControllerHelper

java.lang.Object
  extended by shared.HelperBaseCh4
      extended by shared.HelperBaseCh5
          extended by shared.HelperBaseCh6
              extended by ch6.complexInit.ControllerHelper

public class ControllerHelper
extends HelperBaseCh6

Uses complex form elements. Creates a map of values that have been selected by the user. This map can be accessed in the JSP to simplify initialising the complex elements.

The complex form elements in the bean use annotations to indicate if they are initialised with 'checked' or 'selected'.


Nested Class Summary
 
Nested classes/interfaces inherited from class shared.HelperBaseCh4
HelperBaseCh4.SessionData
 
Field Summary
 
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
 java.lang.String confirmMethod()
          The method that preforms the actions associated with the confirm button.
 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.String editMethod()
          The method that preforms the actions associated with the edit button.
 java.lang.Object getData()
          Accessor that returns the bean.
protected  java.lang.String jspLocation(java.lang.String page)
          Generates the full path to a JSP.
 java.lang.String processMethod()
          The method that preforms the actions associated with the process button.
 void resetNullable()
          Certain form elements might not place data in the query string, if the user does not specify a value.
 
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
 

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

getData

public java.lang.Object getData()
Accessor that returns the 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.


resetNullable

public void resetNullable()
Certain form elements might not place data in the query string, if the user does not specify a value. These fields must be reset, in the event that the user previously specified some values.

Use this method to call the setters for all nullable fields and clear any old values.


jspLocation

protected 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.

editMethod

public java.lang.String editMethod()
The method that preforms the actions associated with the edit button.

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

confirmMethod

public java.lang.String confirmMethod()
The method that preforms the actions associated with the confirm button. This method implements required validation.

If the data is valid, then the next page will be the confirm page. If the data is not valid, then the next page will be the edit page.

If there are errors, they will be displayed in the edit page.

Nullable fields must be cleared before new data is entered by the user. The nullable form elements are radio, checkbox and multiple select lists.

Call the helper base method setCheckedAndSelected to create a map of values that have been chosen by the user. The key will be the user's selection, the value will be either 'checked' or 'selected'. This map will simplify the initialisation of complex elements in the JSP.

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

processMethod

public java.lang.String processMethod()
The method that preforms the actions associated with the process button.

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

doGet

protected void doGet()
              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 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.