package examples.tapestry.page;

import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.callback.ICallback;
import org.apache.tapestry.callback.PageCallback;
import org.apache.tapestry.html.BasePage;

import examples.tapestry.AddService;

public class Home extends BasePage {

	private String arg1_;

	private String arg2_;

	private AddService addService_;

	public String getArg1() {
		return arg1_;
	}

	public void setArg1(String arg1) {
		arg1_ = arg1;
	}

	public String getArg2() {
		return arg2_;
	}

	public void setArg2(String arg2) {
		arg2_ = arg2;
	}

	public AddService getAddService() {
		return addService_;
	}

	public void setAddService(AddService addService) {
		addService_ = addService;
	}

	public void calculate(IRequestCycle cycle) {
		try {
			int result = addService_.add( 
					Integer.parseInt(arg1_), Integer.parseInt(arg2_));
			AddResult next = (AddResult) cycle.getPage("AddResult");
			next.setResult(new Integer(result));
			cycle.activate(next);
		} catch (NumberFormatException e) {
			ICallback callback = new PageCallback(this);
			callback.performCallback(cycle);
		}

	}
}