Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Switching Master Page Dynamically Based Upon Output Format
virgosmart
<p><span style="font-size:12px;">Hello,</span></p><p> </p><p><span style="font-size:12px;">I have a report which has two masterpages, one for web and other for print (xls, pdf, doc etc.). This report sources data from a few DB2 tables and lays it out as a table or a crosstab. I need to choose the correct masterpage based upon the requested output format (e.g. web or xls). </span></p><p> </p><p><span style="font-size:12px;">I have a custom "report runner" servlet that does the basic bootstrapping and calls one of the two "report handlers" viz, OneStepReportRequestHandler - runs/renders the report using the IRunAndRenderTask or TwoStepReportRequestHandler - runs the report using IRunTask and renders the report using IRenderTask. </span></p><p> </p><p><span style="font-size:12px;">Both these classes check the output format and switch the masterpage </span></p><p> </p><p><span style="font-size:12px;">ReportDesignHandle reportDesign = .....;</span></p><p><span style="font-size:12px;"> try {</span></p><p> </p><p><span style="font-size:12px;">Try 1:</span></p><p><span style="font-size:12px;"> DesignElementHandle dataContainer = reportDesign.findElement("MyReportDataTable");
dataContainer.setProperty("masterPage", printMasterPageName);</span></p><p> </p><p><span style="font-size:12px;">Try 2:</span></p><p><span style="font-size:12px;"> SharedStyleHandle containerRenderHandle = dataContainer.getElementFactory().newStyle("hisMastersPage");
containerRenderHandle.setMasterPage(printMasterPageName);
reportDesign.getStyles().add(containerRenderHandle);
dataContainer.setStyle(containerRenderHandle);
}
catch (ContentException e) {
}
catch (NameException e) {
}
catch (StyleException e) {
}
catch (SemanticException e) {
}</span>
</p><p><span style="font-size:12px;">There are no exception thrown any where at runtime.</span></p><p> </p><p><span style="font-size:12px;">The masterpage switching happens correctly if the report is run using OneStepReportRequestHandler (i.e. IRunAndRenderTask) where as the first masterpage defined within the report is always applied if the report is run using the TwoStepReportRequestHandler (i.e. separate IRunTask and IRenderTask approach). </span></p><p> </p><p><span style="font-size:12px;">Where am I going wrong ?</span></p><p> </p><p><span style="font-size:12px;">Other options tried:</span></p><p><span style="font-size:12px;">1) Switching the master page using JavaScript on report's initialize and beforeFactory events.</span></p><p><span style="font-size:12px;"> -- Did not work.</span></p><p><span style="font-size:12px;">2) Keeping a single masterpage</span></p><p><span style="font-size:12px;"> -- Works, but defeats the purpose (I need separate masterpages)</span></p><p> </p><p> </p><p> </p>
Find more posts tagged with
Comments
mwilliams
<p>Is "MyReportDataTable" the first item in the report? The masterpage should be set on the first element in the report and it should change for all elements in the report unless you specify another masterpage for an element that starts on a new page.</p>