场景示例- ShowReportListener-报表展现标签与API
目录

场景示例

示例1

某报表系统只允许用户在工作时间(09:00-18:00)进行报表的打印和导出。非工作时间,用户登录系统后只能进行报表的查看,不能输出:

public class ShowLineReportListener extends ShowReportListener{
    public IShowReport initShowReport(IShowReport isr){
    }
    public ShowReport afterGetShowReport(ShowReport showReport){
          try{
                     SimpleDateFormat df = new SimpleDateFormat("HH:mm");
                     df.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
                     Date beginTime = df.parse("9:00");
                     Date endTime = df.parse("18:00");
                     String currentTimeString = df.format(new Date());
                     Date currentTime = df.parse(currentTimeString);
                     if ((currentTime.after(beginTime)) && (endTime.after(currentTime)))
                            showReport.getViewReport().setNeedPrint("yes");
                     else
                            showReport.getViewReport().setNeedPrint("no");
          }
          catch (ParseException e) {
                     e.printStackTrace();
          }
          return showReport;
    }
}

 

示例2

系统中的普通用户登陆正常显示当前报表,root登陆显示特定报表:

public class ShowLineReportListener extends ShowReportListener{
      @Override
      public ShowReport afterGetShowReport(ShowReport showReport) {
            showReport.getViewReport().setNeedScroll("yes");
            return showReport;
      }
      @Override
      public IShowReport initShowReport(IShowReport isr) {
            HttpSession session = (HttpSession)isr.getAttrs().get("session");
            String id = session.getAttribute("sys_UserID").toString();
            HttpServletRequest request = (HttpServletRequest)isr.getAttrs().get("request");
            if (id.equals("root")){
                  isr.getAttrs().put("res_server_path", "/mis2/reportcenter/res/flexdesigner/reportFiles/11577.raq");//设置所展现的报表资源路径
                  return isr;
            }
            return isr;
      }
 }

注意: showReport.getViewReport()返回ViewReport对象,该对象的get/set方法,可设置所有view:report、view:input、view:html、view:group中的标签属性,具体可参见用户手册中的相关介绍。

参考DEMO

\报表运算客户化\SR监听类\ ShowReportTestListener.java