📄 transactionform.java
字号:
package itso.strutsweb.forms;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import itso.bank.util.AmountConverter;
/**
* Form bean for a Struts application.
* Users may access 6 fields on this form:
* <ul>
* <li>action - [your comment here]
* <li>amount - [your comment here]
* <li>destinationAccount - [your comment here]
* <li>accountID - [your comment here]
* <li>accountBalance - [your comment here]
* <li>transactions - [your comment here]
* </ul>
* @version 1.0
* @author
*/
public class TransactionForm extends ActionForm {
private String action = "ListTransactions";
private String amount = null;
private String destinationAccount = null;
private String accountID = null;
private String accountBalance = null;
private itso.bank.model.TransRecord[] transactions = null;
/**
* Get action
* @return String
*/
public String getAction() {
return action;
}
/**
* Set action
* @param <code>String</code>
*/
public void setAction(String a) {
action = a;
}
/**
* Get amount
* @return String
*/
public String getAmount() {
return amount;
}
/**
* Set amount
* @param <code>String</code>
*/
public void setAmount(String a) {
amount = a;
}
/**
* Get destinationAccount
* @return String
*/
public String getDestinationAccount() {
return destinationAccount;
}
/**
* Set destinationAccount
* @param <code>String</code>
*/
public void setDestinationAccount(String d) {
destinationAccount = d;
}
/**
* Get accountID
* @return String
*/
public String getAccountID() {
return accountID;
}
/**
* Set accountID
* @param <code>String</code>
*/
public void setAccountID(String a) {
accountID = a;
}
/**
* Get accountBalance
* @return String
*/
public String getAccountBalance() {
return accountBalance;
}
/**
* Set accountBalance
* @param <code>String</code>
*/
public void setAccountBalance(String a) {
accountBalance = a;
}
/**
* Get transactions
* @return itso.bank.model.TransRecord[]
*/
public itso.bank.model.TransRecord[] getTransactions() {
return transactions;
}
/**
* Set transactions
* @param <code>itso.bank.model.TransRecord[]</code>
*/
public void setTransactions(itso.bank.model.TransRecord[] t) {
transactions = t;
}
/**
* Constructor
*/
public TransactionForm() {
super();
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
// Reset values are provided as samples only. Change as appropriate.
action ="ListTransactions";
amount = null;
destinationAccount = null;
accountID = null;
accountBalance = null;
transactions = null;
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (action != null && action.trim().length() != 0) {
if ("Deposit".equals(action)
|| "Withdraw".equals(action)
|| "Transfer".equals(action)) {
if (amount == null || amount.trim().length() == 0)
errors.add(
ActionErrors.GLOBAL_ERROR,
new ActionError("error.missing.amount"));
else
try {
java.math.BigDecimal a = AmountConverter.fromString(amount);
if (a.compareTo( new java.math.BigDecimal(0.00) ) <= 0)
errors.add(
ActionErrors.GLOBAL_ERROR,
new ActionError("error.invalid.amount"));
} catch (Exception e) {
errors.add(
ActionErrors.GLOBAL_ERROR,
new ActionError("error.invalid.amount"));
}
}
if ("Transfer".equals(action)) {
if (destinationAccount == null
|| destinationAccount.trim().length() == 0)
errors.add(
ActionErrors.GLOBAL_ERROR,
new ActionError("error.missing.destinationAccount"));
}
}
return errors;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -