package ${entity.getPackage('tapestry.page')};

import java.io.*;
import java.util.*;

import org.apache.tapestry.IActionListener;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;
import org.asyrinx.brownie.core.query.exp.IExpression;
import org.asyrinx.brownie.tapestry.page.ReloadablePage;
import org.asyrinx.joey.tapestry.page.CaptionablePage;

import ${entity.getPackage('entity')}.*;
import ${entity.getPackage('service')}.*;
#foreach ($importFqn in ${entity.getImports()})
import ${importFqn};
#end

/**
 */
#set( $pageListClassName = "${tapestryPageListPrefix}${entity.getName()}${tapestryPageListSuffix}" )
public abstract class ${pageListClassName} extends BasePage implements CaptionablePage, ReloadablePage {

	public ${pageListClassName}(){
		super();
	}
	
    public String getPageCaption() {
        return "${entity.getLabel()} ˆê——";
    }
	
	private List targets = null;
	
	public List getTargets(){
		return this.targets;
	}

	public void setTargets(List targets){
		this.targets = targets;
	}
	
	private IExpression condition = null;
	
	public IExpression getCondition(){
		return this.condition;
	}
	
	public void setCondition(IExpression condition){
		this.condition = condition;
	}

#set( $serviceName = "${servicePrefix}${entity.getName()}${serviceSuffix}" )
	abstract public ${serviceName} get${serviceName}();
	
    public void clickSearch(IRequestCycle cycle) {
        loadTargets();
    }

    public void loadTargets() {
        this.targets = get${serviceName}().select(getCondition());
    }

    public void renderPage(IMarkupWriter writer, IRequestCycle cycle) {
        loadTargets();
        super.renderPage(writer, cycle);
    }

    public void reload() {
        loadTargets();
    }
}
