Home

 

Completing the actions

The completed code is provided in C:\7672code\struts\action:

The LogonAction is already complete.

The LogoffAction has three lines in the execute method try clause:

//Destroy the objects in session.

request.getSession().setAttribute("ssn", null);

request.getSession().setAttribute("ITSOBank", null);

Complete the AccountDetailsAction class execute method:

CustomerAccountForm customerAccountForm = (CustomerAccountForm) form;

String accountId = customerAccountForm.getAccountId();

try {

// Retrieve the account from the bank

Bank bank = (Bank)request.getSession().getAttribute("ITSOBank");

Account accountBean = bank.searchAccountByAccountNumber(accountId);

// Add the account info to request scope

request.setAttribute("account", accountBean);

} catch (Exception e) {

// Report the error using the appropriate name and ID.

errors.add("error", new ActionMessage("errors.systemError"));

}

......

forward = mapping.findForward("failure");

Complete the PerformTransactionAction class execute method:

TransactForm transactForm = (TransactForm) form;

String accountId = transactForm.getAccountId();

String amountf = transactForm.getAmount();

BigDecimal amount = null;

try {

// convert the amount and perform withdraw or deposit

Bank bank = (Bank)request.getSession().getAttribute("ITSOBank");

amount = new BigDecimal(amountf);

if ( amount.compareTo(new BigDecimal(0)) < 0 ){

bank.withdraw(accountId, amount.negate());

} else {

bank.deposit(accountId, amount);

}

} catch (NumberFormatException e) {

errors.add("amount", new ActionMessage("error.amount"));

} catch (InvalidTransactionException e) {

errors.add("amount", new ActionMessage("error.amount"));

}

......

forward = mapping.findForward("failure");

Import java.math.BigDecimal and itso.rad75.bank.exception.InvalidTransactionException.
ibm.com/redbooks