FileDocCategorySizeDatePackage
TokenAction.javaAPI DocApache Struts 2.0.9 Apps3044Mon Jul 23 13:43:26 BST 2007org.apache.struts2.showcase.token

TokenAction

public class TokenAction extends com.opensymphony.xwork2.ActionSupport
Example to illustrate the token and token-session interceptor.

Fields Summary
private static final long
serialVersionUID
private int
amount
Constructors Summary
Methods Summary
public java.lang.Stringexecute()


         
        // transfer from source to destination

        Integer balSource = (Integer) ActionContext.getContext().getSession().get("balanceSource");
        Integer balDest = (Integer) ActionContext.getContext().getSession().get("balanceDestination");

        Integer newSource = new Integer(balSource.intValue() - amount);
        Integer newDest = new Integer(balDest.intValue() + amount);

        ActionContext.getContext().getSession().put("balanceSource", newSource);
        ActionContext.getContext().getSession().put("balanceDestination", newDest);
        ActionContext.getContext().getSession().put("time", new Date());

        Thread.sleep(2000); // to simulate processing time

        return SUCCESS;
    
public intgetAmount()

        return amount;
    
public java.lang.Stringinput()

        // prepare input form
        Integer balSource = (Integer) ActionContext.getContext().getSession().get("balanceSource");
        Integer balDest = (Integer) ActionContext.getContext().getSession().get("balanceDestination");

        if (balSource == null) {
            // first time set up an initial account balance
            balSource = new Integer(1200);
            ActionContext.getContext().getSession().put("balanceSource", balSource);
        }

        if (balDest == null) {
            // first time set up an initial account balance
            balDest = new Integer(2500);
            ActionContext.getContext().getSession().put("balanceDestination", balDest);
        }

        return INPUT;
    
public voidsetAmount(int amount)

        this.amount = amount;