package com.javaeye.jert.action.user.report;
import com.javaeye.jert.domain.ReportInstance;
import com.javaeye.jert.domain.query.QueryParameter;
/**
* @author Quake Wang
* @since 2004-12-27
* @version $Revision: 1.6 $
*/
public class GenerateReport extends BaseReportAction {
protected ReportInstance reportInstance = new ReportInstance();
public String execute() throws Exception {
if(!isValidateParameters()) return INPUT;
reportInstance.setCountOnEachPage(userPrefs.getCountOnEachPage().intValue());
reportInstance.setReportDefinition(reportDefinition);
reportInstance.generateItems(parameters);
return SUCCESS;
}
//TODO can we move this validation to the xwork validate framework?
protected boolean isValidateParameters() {
boolean pass = true;
for (int i = 0; i < parameters.length; i++) {
QueryParameter parameter = parameters[i];
if(!parameter.getParameterDefinition().isOptional() && parameter.getQueryValue() == null){
addActionError(parameter.getParameterDefinition().getName() + " is required");
//addFieldError("parameters[" + i + "].value", "required");
pass = false;
}
}
return pass;
}
public ReportInstance getReportInstance() {
return reportInstance;
}
public void setReportInstance(ReportInstance reportInstance) {
this.reportInstance = reportInstance;
}
}