api展现分页报表,翻页功能条
◆ 背景说明
◆ 应用举例
一张有分页的报表,命名为test.raq,在test.jsp页面中写如下代码:
<%@ page contentType=”text/html;charset=gb2312″ %>
<%@ page import=”java.io.*”%>
<%@ page import=”com.runqian.report4.usermodel.*”%>
<%@ page import=”com.runqian.report4.model.*”%>
<%@ page import=”com.runqian.report4.view.html.*”%>
<%@ page import=”com.runqian.report4.util.*”%>
<%@ page import=”com.runqian.report4.view.excel.*”%>
<%
//第一步,读取报表模板
InputStream fis=application.getResourceAsStream(”/reportFiles/test.raq”);
ReportDefine rd = (ReportDefine)ReportUtils.read( fis );
//第二步,运算报表
Context context = new Context();
Engine enging = new Engine( rd, context);
IReport iReport = enging.calc();
//第三步,调用api实现报表分页
int currPage = 1;//得到当前页数
if( request.getParameter(”currPage”)!=null ){
currPage = Integer.parseInt( request.getParameter(”currPage”) );
}
//根据保存在session中的分页信息,我们就可以实现点击下一页而不用再计算了:
PageBuilder pb = (PageBuilder)session.getAttribute(”runqian_pagebuilder”);
if( pb==null ){
//第一次展现报表报表调用分页信息,并保存供下次分页用
pb = new PageBuilder(iReport);//根据IReport对象构建分页对象PageBuilder
session.setAttribute(”runqian_pagebuilder”,pb);
}
IReport iReporTemp = pb.getPage(currPage);//根据分页信息取得需要展现的该页报表对象
int totalPage = pb. getPageCount();//取得总页数
//第四步,展现(用分页结果展现)
HtmlReport hReport = new HtmlReport( iReporTemp,”report1″ );
out.print(hReport.generateHtml());
%>
<table>
<tr>
<td>
<a href=”test.jsp?currPage=1″>首页</a>
</td>
<td>
<a href=” test.jsp?currPage=<%=currPage-1%>”>上一页</a>
</td>
<td>
<a href=” test.jsp?currPage=<%=currPage+1%>”>下一页</a>
</td>
<td>
<a href=” test.jsp?currPage=<%=totalPage%>”>尾页</a>
</td>
</tr>
</table>