如何将一个List对象传递给皕杰报表在页面展示
1.创建List对象,访问皕杰报表
List list = systemService.find(hql); //查询结果集,放到list对象中
request.getSession().setAttribute("list", list);//结果集放到session容器中,
注意:为啥将结果集放到session容器,而不放入request对象中?查询的结果集过多,涉及到翻页,使用request对象,翻页后不能获得list对象中的内容。
注意:为啥将结果集放到session容器,而不放入request对象中?查询的结果集过多,涉及到翻页,使用request对象,翻页后不能获得list对象中的内容。
request.getRequestDispatcher("/ReportEmitter?rpt=contractState.brt").forward(request, response);
2.继承ContractStateDataSet,将结果集放到报表中
package bios.report.user.dev.demo.dataset;
2.继承ContractStateDataSet,将结果集放到报表中
package bios.report.user.dev.demo.dataset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpSession;
import bios.report.engine.api.CustomDataSet;
import bios.report.engine.api.UserContext;
import com.dhcc.itsm.document.model.Contract;
import com.dhcc.itsm.document.model.ContractPay;
import com.dhcc.itsm.document.model.ContractSettlement;
/**
* @author dhcc
*/
public class ContractStateDataSet implements CustomDataSet{
private String[] metaData;
private List<Contract> conList = new ArrayList<Contract>();
@SuppressWarnings("unchecked")
private List data;
public String[] getMetaData() {
return metaData;
}
public int getRowCount() {
return data.size();
}
public Object[] getRowData(int rowIndex) {
return (Object[])data.get(rowIndex);
}
@SuppressWarnings("unchecked")
public void applyParams(Object[] arg0) {
HttpSession req = UserContext.getCurrentUserContext().getRequest().getSession();
conList = (List<Contract>) req.getAttribute("list");
metaData = new String[]{"合同名称","合同金额","结算日期","结算金额","结算合计","付款日期","付款金额","付款合计","施工单位"};
data = new ArrayList();
try {
if(conList != null && !conList.isEmpty()){
for(int i=0;i<conList.size();i++){
Contract con = conList.get(i);
String[] settleStr = getSettle(con.getSettleSet());//结款信息放到字符串中
String[] payStr = getPay(con.getPaySet()); //付款信息放到字符串中
data.add(new Object[]{con.getContractName(),con.getMoney(),settleStr[0],settleStr[1],
Double.parseDouble(settleStr[2]),payStr[0],payStr[1],Double.parseDouble(payStr[2]),con.getYiFang()});
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public List<Contract> getConList() {
return conList;
}
public void setConList(List<Contract> conList) {
this.conList = conList;
}
/**
* 结款信息放到放到字符串中
* @param settleList
* @return
*/
@SuppressWarnings("unchecked")
private String[] getSettle(Set<ContractSettlement> settleSet){
String[] settleStr = new String[3];
String settleTemp = "\n";//结算日期
String moneyStr ="\n";//结算金额
double settleSum = 0;//结款总金额
if(settleSet != null && !settleSet.isEmpty()){
Iterator it = settleSet.iterator();
while(it.hasNext()){
ContractSettlement settle = (ContractSettlement) it.next();
settleTemp += settle.getBalanceDate() +"\n\n";
moneyStr += settle.getMoney()+"\n\n";
settleSum +=Double.parseDouble(settle.getMoney());
}
}
settleStr[0]=settleTemp;
settleStr[1]=moneyStr;
settleStr[2]=String.valueOf(settleSum);
return settleStr;
}
/**
* 付款信息放到放到字符串中
* @param settleList
* @return
*/
@SuppressWarnings("unchecked")
private String[] getPay(Set<ContractPay> paySet){
String[] payStr = new String[3];
String payTemp = "\n";//
String moneyStr ="\n";
double paySum = 0;//付款总金额
if(paySet != null && !paySet.isEmpty()){
Iterator it = paySet.iterator();
while(it.hasNext()){
ContractPay pay = (ContractPay) it.next();
payTemp += pay.getPayDate() +"\n\n";
moneyStr += pay.getMoney()+"\n\n";
paySum +=Double.parseDouble(pay.getMoney());
}
}
payStr[0]=payTemp;
payStr[1]=moneyStr;
payStr[2]=String.valueOf(paySum);
return payStr;
}
}
皕杰报表
posted on 2012-09-28 16:15 kangxuebin 阅读(287) 评论(0) 编辑 收藏 举报