public String doProcessAction() { // Type Java code that runs when the component is clicked // TODO: Return outcome that corresponds to a navigation rule // return "customerDetails"; // return "logout"; // global String amountstring = (String)getRequestScope().get("amount"); System.out.println("deposit/withdraw amount: " + amountstring); try { BigDecimal amount = new BigDecimal(amountstring); if (amount.scale() > 2) throw new Exception("Only 2 digits allowed for cents"); Account account = getAccount(); BigDecimal balance = account.getBalance(); if (amount.doubleValue() == 0) { throw new Exception("Amount is zero"); } else if (amount.doubleValue() > 0) { balance = balance.add(amount); } else { if (balance.compareTo(amount.abs()) < 0) throw new Exception("Withdraw amount too big"); balance = balance.add(amount); } account.setBalance(balance); AccountManager accountManager = (AccountManager)getManagedBean("accountManager"); accountManager.updateAccount(account); System.out.println("deposit/withdraw balance: " + balance); // create transaction TransactionManager transactionManager = (TransactionManager)getManagedBean("transactionManager"); Transaction t = new Transaction(); t.setId( (new com.ibm.ejs.util.Uuid()).toString() ); t.setAmount(amount.abs()); t.setTransTime( new Timestamp(System.currentTimeMillis()) ); if (amount.doubleValue() > 0) t.setTransType("Credit"); else t.setTransType("Debit"); t.setAccount(account); transactionManager.createTransaction(t); transactionList = null; getTransactionList(); getRequestScope().put("amount",""); } catch (NumberFormatException e) { getFacesContext().addMessage("amount", new FacesMessage("Bad amount")); } catch (Exception e) { getFacesContext().addMessage("amount", new FacesMessage("Deposit/withdraw failed: " + e.getMessage())); } return ""; }