Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
calling BIRT Report Viewer from Struts Action class
Reji
Hi,
I have integrated struts and BIRT, and it's working fine...
I am using HTMLRenderOption and 'run' to get the report..That much is working fine..
Now what I want is, the report to come in BIRT Report Viewer (with frameset).
This is my code in struts action class..
//get the parameters passed from jsp form..
//do some work on the params
......
// configure engine
EngineConfig engineConfig = new EngineConfig();
...
ServletContext sc = req.getSession().getServletContext();
IPlatformContext context = new PlatformServletContext( sc );
engineConfig.setPlatformContext( context );
Platform.startup( engineConfig );
//create factory and create birt engine
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
IReportEngine birtEngine = factory.createReportEngine( engineConfig);
//put params from JSP in to a hashmap
HashMap params = new HashMap();
params.put("p_1",param1);
params.put("p_2",param2);
//create report design
design = birtEngine.openReportDesign(sc.getRealPath("/Reports")+"/"+"myreport.rptdesign");
//create task
IRunAndRenderTask task = birtEngine.createRunAndRenderTask(design);
HTMLRenderOption options = new HTMLRenderOption();
javax.servlet.ServletOutputStream sosStream = null;
sosStream = resp.getOutputStream();
options.setOutputStream(sosStream);
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
task.setParameterValues(params);
task.validateParameters();
task.setRenderOption(options);
task.run();
task.close();
birtEngine.destroy();
//for struts...
return mapping.findForward(null);
Since I am not giving any explicit url I can not give some thing like "frameset?__report=Report/myreport.rptdesign"
is there any provision to view the report in BIRT Report Viewer by setting parameters in "options" "task" or soome where?
One way is to use
********
<%@ taglib uri="/WEB-INF/birt.tld" prefix="birt" %>
<body>
<birt:viewer id="birtViewer" reportDesign="/test.rptdesign" showParameterPage="true" pattern="frameset"
height="450" width="700" format="html">
</birt:viewer>
</body>
**********
but in this case i wont have the flexibility to manipulate parameters passed from JSP ....
Thanx in advance,
regs
reji
Find more posts tagged with
Comments
Virgil Dodson
Hi Reji,<br />
<br />
I have not personally worked BIRT into Struts framework, however a couple of people have and there are examples in the DevShare area on BIRT Exchange. Most seem to use the BIRT Engine APIs, however one of them seems to be integrating the WebViewerExample. Take a look at the code example at <a class='bbc_url' href='
http://www.birt-exchange.com/devshare/designing-birt-reports/424-integrating-birt-with-hibernate-and-struts/#'>Integrating
BIRT with Hibernate and Struts - Designs & Code - BIRT Exchange</a> to see if that helps.
dsusca
How about if you do something like this:
in your jsp use the birt viewer tag combined with jsp code:
<birt:viewer id="birtViewer" reportDesign="/test.rptdesign" showParameterPage="true" pattern="frameset"
height="450" width="700" format="html">
<% for(int i=0;i<(Integer)request.getAttribute("numberOfParams");i++{%>
<birt:param name="<%=request.getAttribute("param" + i)%> .... />
<%}%>
</birt:viewer>
and in your pre-action you set the params as request attributes.
Not very elegant, but a solution still...
On another note, I am very interested how you integrated BIRT with struts. Did you just add the ReportEngine libraries in your web-inf/lib? Are any more steps necessary?
I'm struggling with this right now and I would really appreciate some help on this issue.
Reji
Thank you to u 2...
My webviewer stuff is not working ..when i say 'WebViewer.display(...) it says 'Application is not initialised'...
now I am trying in another way..
dsusca, u can deploy struts blank.war and merge the web.xml of WebViewerExample with struts application's web.xml....u'll have to copy the following folders..
-report
-scriptlib
-webcontent
-WEB-INF (make sure web.xml is the merged one..)
now from the action class u can do actionforward, and give url as /frameset?__report=Report/test1.rptdesign
i think u can append parameters with this url and these params wont b visible in url address window...
kevin23_hy
hi,dear vdodson:
birt-viewer is not support height/width value of percentage of birt tag,eg. <birt:viewer height="80%" width="100%" ></birt:viewer>, i tryed throws "illegal format",so pls tell has any resolution to support this,i think is quite important; i used birt2.5 viewer.