how to get using RE API for birt report in struts2, trying to render birt report with pagination(paginated html) with navbar

29 Views Asked by At

I am fetching birt report using RE API using birt engine in struts2, working fine but pagination navbar is not showing on reports. please give suggestion with example in java.

I have .rptdesign File which is runnable file. i don't have IReportDocument type file. due to which "org.eclipse.birt.report.engine.api.EngineException: Render task is not finished." error occured. trying to achive pagination for birt report in struts2. please give any reference with example for pagination in birt report.

code i am using as given below.


public class BirtEngine {
    private static Logger LOGGER = LogManager.getLogger(BirtEngine.class);
    private static IReportEngine birtEngine = null;
    private static Properties configProps = new Properties();

    public static synchronized IReportEngine getBirtEngine(ServletContext sc) {
        if (birtEngine == null)
        {
            EngineConfig config = new EngineConfig();
            
            config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, BirtEngine.class.getClassLoader());
            config.setEngineHome("");
            IPlatformContext context = new PlatformServletContext( sc );
            config.setPlatformContext( context );
            try
            {
                Platform.startup( config );
            }
            catch ( BirtException e )
            {
                LogUtils.error(BirtEngine.class, e);
            }
            IReportEngineFactory factory = (IReportEngineFactory) Platform
                    .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
            birtEngine = factory.createReportEngine( config );
        }
        return birtEngine;
    }

    public static synchronized void destroyBirtEngine() {
        if (birtEngine == null) {
            return;
        }
        birtEngine.destroy();
        Platform.shutdown();
        birtEngine = null;
    }
    
    public static IRenderOption getRenderOption(String format,ServletContext sc){
        IRenderOption option =null;
        if(format.equals("html")){
            option = getHtmlRenderOptiopn(sc);
        }else{
            option= null;
        }
        return option;
    }
    private static HTMLRenderOption getHtmlRenderOptiopn(ServletContext sc){
        HTMLRenderOption option = new HTMLRenderOption();
        
        option.setHtmlPagination(true);
        
        option.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
        option.setImageHandler(new HTMLServerImageHandler());
        option.setBaseImageURL(sc.getContextPath()+"/birt/images");
        option.setImageDirectory(sc.getRealPath("birt")+"/images");
        return option;
    }
}

--------------------------------------------
public class RunBirt{
    private IReportEngine birtReportEngine = null;
    private static Logger logger = LoggerFactory.getLogger(RunBirt.class);
    public String printReport(ServletContext sc,String reportFormat,Map<String,Object> reportParameter,String reportDesign) throws ServletException{
        this.birtReportEngine = BirtEngine.getBirtEngine(sc);
        IReportRunnable design;
        try
        {
            //Open report design
            design = birtReportEngine.openReportDesign( reportDesign );
            //create task to run and render report
            IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask( design );
            task.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, RunBirt.class.getClassLoader());
           
            
            IGetParameterDefinitionTask parameterDefinitionTask = birtReportEngine.createGetParameterDefinitionTask(design);
            HashMap<String, String> declaredParam = parameterDefinitionTask.getDefaultValues();
            Set<Map.Entry<String, String>> set = declaredParam.entrySet();
            if(!reportParameter.isEmpty()){
                for(Map.Entry<String, String> entry:set){
                    
                    task.setParameterValue(entry.getKey(), reportParameter.get(entry.getKey()) == null ? reportParameter.get(entry.getKey()) : reportParameter.get(entry.getKey()));
                }
                task.validateParameters();
            }
            //set output options
            IRenderOption options = BirtEngine.getRenderOption(reportFormat,sc);
            ByteArrayOutputStream oStream = new ByteArrayOutputStream();
            options.setOutputStream(oStream);
            task.setRenderOption(options);
            //run report
            task.run();
            //Check if error(s) is generated by BIRT engine.
            if(null!=task.getErrors() && task.getErrors().size()>0){System.out.println(task.getErrors());
                logger.error(task.getErrors().toString());
                task.close();
                String errorMsg = Util.readFileContent("ErrorPage.html");
                
                return errorMsg;
                
            }
            task.close();
            return oStream.toString("UTF-8");
        }catch (Exception e){
            e.printStackTrace();
            LogUtils.error(this.getClass(), e);
            throw new ServletException( e );
        }
    }
}

0

There are 0 best solutions below