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)
params displayText returns null with APIs
vivash
For list/dropdown parameters I'm using params["xx"].displayText to show the value the user selected. This works fine when Birt executes the report (either in the Birt Viewer and when exporting from Birt Viewer to other format), but it returns "null" if I use Birt Engine API (IRenderTask) to execute the report.
Is this a known bug - any workaround?
Thanks,
-vivek
Find more posts tagged with
Comments
JasonW
Vivek,
Use a parameter definition task before you run the report:
IGetParameterDefinitionTask ptask = engine.createGetParameterDefinitionTask( design );
//String myDefaultValue = (String)ptask.getDefaultValue("parm1");
Collection selectionList = ptask.getSelectionList("parm1");
String myDisplayText = "";
if ( selectionList != null )
{
for ( Iterator sliter = selectionList.iterator( ); sliter.hasNext( ); )
{
IParameterSelectionChoice selectionItem = (IParameterSelectionChoice) sliter.next( );
String lbl = selectionItem.getLabel();
String value = (String)selectionItem.getValue( );
if( value.compareTo("value2") == 0 ){
myDisplayText = selectionItem.getLabel();
break;
}
}
}
then in the run task set the display text like
task.setParameterDisplayText("param",myDisplayText)
Jason
vivash
Thanks Jason.
Is this a workaround or this is how it's supposed to work? Iterating and finding out what parameter is the selection list and then setting it's displaytext seems like an overkill to me. I use params["xx"].displaytext in the report script itself, so I hopping that it Birt Engine should automatically set the display text value internally. Should I file a bug for this?
-vivek
JasonW
This is how it works currently. You can file an enhanement request if you would like.
Jason
tb1981
Can somebody explain where to put this code?
I don't have much experience with birt.
Thnx for your help
JasonW
That code is for an report engine API example. You can put it in any API program that uses the RE API.
For example here is a command line java app to run the BIRT report engine:
package REAPI;
import java.util.logging.Level;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EXCELRenderOption;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.PDFRenderOption;
public class RunAndRenderTask {
public void runReport() throws EngineException
{
IRunAndRenderTask task=null;
IReportEngine engine=null;
EngineConfig config = null;
try{
//System.setProperty("java.io.tmpdir", "c:/temp/test/testsampledb");
config = new EngineConfig( );
config.setLogConfig("c:/dwn", Level.INFO);
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, this.getClass().getClassLoader());
config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, "C:\\work\\workspaces\\2.6.2workspaces\\BIRT Metal\\APIs\\Reports\\eventjar.jar");
config.setBIRTHome("C:\\birt\\birt-runtime-2_6_2\\birt-runtime-2_6_2\\ReportEngine");
//config.setLogConfig(null, Level.FINEST);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
IReportRunnable design = null;
//Open the report design
design = engine.openReportDesign("Reports/dataseteventhandler.rptdesign");
task = engine.createRunAndRenderTask(design);
//task.setParameterValue("Top Count", (new Integer(5)));
task.validateParameters();
HTMLRenderOption options = new HTMLRenderOption();
options.setImageDirectory("./");
options.setOutputFileName("output/resample/eventhandlerjar.html");
options.setOutputFormat("html");
//PDFRenderOption options = new PDFRenderOption();
//options.setOutputFileName("output/resample/topn.pdf");
//options.setSupportedImageFormats("PNG;GIF;JPG;BMP;SWF;SVG");
//options.setOutputFormat("pdf");
//EXCELRenderOption options = new EXCELRenderOption();
//options.setOutputFormat("xls");
//options.setOutputFileName("output/resample/customers.xls");
//options.setWrappingText(true);
task.setRenderOption(options);
task.run();
task.close();
engine.destroy();
}catch( Exception ex){
ex.printStackTrace();
}
finally
{
if ( !task.getErrors( ).isEmpty( ) )
{
for ( Object e : task.getErrors( ) )
{
( (Exception) e ).printStackTrace( );
}
}
Platform.shutdown( );
System.out.println("Finished");
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
RunAndRenderTask ex = new RunAndRenderTask( );
ex.runReport();
System.exit(0);
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
This is just an example and if your app needs to run multiple reports you should only start the platform once for the life of the application and shut it down when you are finished.
Jason