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)
Best way to programmatically embed text into report
dansh
Hi
I have a report that will require chunks of text (that will be created dynamically) to be embedded from a Java program that runs the report.
Is there a way I can put a text object into the design and then somehow get hold that of that object in my Java program. If this is possible I assume I would be able to insert text into that text object.
Is this the best way to do this?
A code snippet would be gratefully accepted.
Thanks in advance.
Find more posts tagged with
Comments
JasonW
If you are using the API you can add an object to the appcontext of the report engine, which can then be retrieved when the report is running.
For example (RE API):
IReportEngine engine=null;
EngineConfig config = null;
//config.setRourcePath()
SampleClass dl = new SampleClass();
try{
config = new EngineConfig( );
HashMap hm = config.getAppContext();
hm.put( "sample", dl);
config.setAppContext(hm);
config.setBIRTHome("C:\\birt\\ReportEngine");
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
The dummy object can now be called in any birt expression like:
"Test My Sample Object: " + sample.getString();
You can also call it like:
reportContext.getAppContext().get("sample").getString();
Jason
dansh
Thanks so much for replying but I would really appreciate it if you could clarify.
How exactly do I get hold of the text object?
And then how do I set its value?
Thanks again.
JasonW
In that example you do not need to get the text object of the report. You are loading the object in the report context before you run the report. Then you are using an expression to retrieve the object loaded. The expression could be used in a data item a text item etc.
Jason