package examples.tapestry.page;

import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.valid.ValidationDelegate;

import examples.tapestry.CalcService;

public class Home extends BasePage {
    private CalcService _service;
    private int _arg1;
    private int _arg2;
    
    public void setArg1(int arg1) {
    	_arg1 = arg1;
    }
    public int getArg1() {
    	return _arg1;
    }
    public void setArg2(int arg2) {
        _arg2 = arg2;
    }
    public int getArg2() {
        return _arg2;
    }

    protected void initialize() {
        super.initialize();
  //      this.setArg1(0);
//        this.setArg2(0);
    }

    public void calculate(IRequestCycle cycle) {
        int result = _service.calc2( getArg1(), getArg2() );
        ValidationDelegate delegate = (ValidationDelegate)getBeans().getBean("delegate");
        if( delegate.getHasErrors() ){
            return ;
        }
        Result next = (Result) cycle.getPage("Calc");
        next.setResult(result);
        cycle.activate(next);
    }
    public void setService( CalcService service ) {
        this._service = service;
    }
}