Version 4.10.0

hirondelle.web4j.action
Class ActionTemplateShowAndApply

Object
  extended by hirondelle.web4j.action.ActionImpl
      extended by hirondelle.web4j.action.ActionTemplateShowAndApply
All Implemented Interfaces:
Action

public abstract class ActionTemplateShowAndApply
extends ActionImpl

Template for "first show, then validate and apply" groups of operations.

A good example is a page allowing the user to change their preferences : from the point of view of each user, there is only one set of user preferences. Often, a single form can be used to allow editing of preferences. Here, there is no listing of multiple items.

There are two operations in such cases :


Field Summary
static RequestParameter SUPPORTED_OPERATION
          The operations supported by this template.
 
Fields inherited from class hirondelle.web4j.action.ActionImpl
DATA, ERRORS, ITEM_FOR_EDIT, ITEMS_FOR_LISTING, MESSAGES, USER_ID
 
Constructor Summary
protected ActionTemplateShowAndApply(ResponsePage aForward, ResponsePage aRedirect, RequestParser aRequestParser)
          Constructor.
 
Method Summary
protected abstract  void apply()
          Validate the user input, and then apply an edit to the database.
 ResponsePage execute()
          Template method.
protected abstract  void show()
          Show the input form.
protected abstract  void validateUserInput()
          Validate items input by the user into a form.
 
Methods inherited from class hirondelle.web4j.action.ActionImpl
addError, addError, addError, addMessage, addMessage, addToRequest, addToSession, copyFromSessionToRequest, createSessionAndCsrfToken, endSession, getErrors, getExistingSession, getFromSession, getIdParam, getIdParams, getLocale, getLoggedInUserName, getMessages, getOperation, getOrderBy, getParam, getParamUnsafe, getRequestParser, getResponsePage, getTimeZone, getUserId, hasErrors, removeFromSession, setResponsePage
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUPPORTED_OPERATION

public static final RequestParameter SUPPORTED_OPERATION
The operations supported by this template.

The supported operations are :

The source of the Operation is described by ActionImpl.getOperation().

Constructor Detail

ActionTemplateShowAndApply

protected ActionTemplateShowAndApply(ResponsePage aForward,
                                     ResponsePage aRedirect,
                                     RequestParser aRequestParser)
Constructor.

Parameters:
aForward - used for Operation.Show operations, and also for failed Operation.Apply operations. This is the default response.
aRedirect - used for successful Operation.Apply operations.
aRequestParser - passed to the superclass constructor.
Method Detail

execute

public ResponsePage execute()
                     throws AppException
Template method.

In order to clearly understand the operation of this method, here is the core of its implementation, with all abstract methods in italics :

    if ( Operation.Show == getOperation() ){
      show();
    }
    else if ( Operation.Apply == getOperation() ){
      validateUserInput();
      if( ! hasErrors() ){
        apply();
        if ( ! hasErrors() ){
          setResponsePage(fRedirect);
        }
      }
    }
   

Specified by:
execute in interface Action
Specified by:
execute in class ActionImpl
Throws:
AppException

show

protected abstract void show()
                      throws AppException
Show the input form.

The form may or may not be populated.

Throws:
AppException

validateUserInput

protected abstract void validateUserInput()
                                   throws AppException
Validate items input by the user into a form.

Applied to Operation.Apply. If an error occurs, then addError must be called.

Throws:
AppException

apply

protected abstract void apply()
                       throws AppException
Validate the user input, and then apply an edit to the database. If an error occurs, then addError must be called.

Throws:
AppException

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.