Help with addScriptableJavaObject method [message #122924] |
Wed, 01 February 2006 18:37  |
Eclipse User |
|
|
|
Originally posted by: m_terk.yahoo.com`
I have been looking for examples of how to use the addScriptableJavaObject
method for IRunAndRenderTask class. I am using the ReportEngine (R2) and I
want to pass an object to my report. I think I am doing the right things
according to documentations but I keep getting an error that says:
org.eclipse.birt.data.engine.core.DataException: A BIRT exception
occurred: Error evaluating Javascript expression. Script engine error:
TypeError: getStatus is not a function.
Script source: null, line: 0, text:
<compiled script>. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError:
getStatus is not a function.
Script source: null, line: 0, text:
<compiled script>
at
org.eclipse.birt.data.engine.core.DataException.wrap(DataExc eption.java:113)
at
org.eclipse.birt.data.engine.impl.BytecodeExpression.evaluat e(BytecodeExpression.java:53)
Now getStatus (which I think is the cause of the problem) is a method in
my class. The java code I use to send the object is as follows:
Object obj = new ProcessedFilter();
task.addScriptableJavaObject("pFilter",obj);
ProcessedFilter is trivial:
Public class ProcessedFilter {
String getStatus() {return "p";}
void setStatus(String s) {return;}
}
And in my JavaScript all I have is pFilter.getStatus();
I think I am missing something simple but I can't find any full examples
I can try.
Thanks
M. Terk
|
|
|
Re: Help with addScriptableJavaObject method [message #122932 is a reply to message #122924] |
Wed, 01 February 2006 18:58   |
Eclipse User |
|
|
|
Michael,
Here is an example
ProcessFilter
public class ProcessFilter {
public String getStatus(){
return("Test String");
}
}
Code to run report
import java.util.HashMap;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.engine.api.EngineConstants;
public class ExecuteReport {
static void executeReport() throws EngineException
{
//Engine Configuration - set and get temp dir, BIRT home, Servlet context
EngineConfig config = new EngineConfig();
config.setEngineHome( "C:/birt-runtime-2_0_0/birt-runtime-2_0_0/Report
Engine" );
//Create the report engine
ReportEngine engine = new ReportEngine( config );
//Open a report design - use design to modify design, retrieve embedded
images etc.
IReportRunnable design =
engine.openReportDesign("C:/work/test/processfilter.rptdesign ");
//Create task to run the report - use the task to execute and run the
report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
config.setTempDir("c:/work/test/tmp");
//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setImageDirectory("image");
HashMap contextMap = new HashMap();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
task.setAppContext( contextMap );
ProcessFilter pf = new ProcessFilter();
task.addScriptableJavaObject("pFilter", pf);
//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();
//options.setOutputStream(System.out);
options.setOutputFileName("c:\\work\\test\\pfilter.html");
options.setOutputFormat("html");
task.setRenderOption(options);
//run the report and destroy the engine
task.run();
engine.destroy();
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Written by Eclipse BIRT 2.0 -->
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3" id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.0.0 Build
<20060123-1141></property>
<property name="units">in</property>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<value-of>new
Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<data id="5">
<expression name="valueExpr">pFilter.getStatus();</expression>
</data>
</body>
</report>
Jason Weathersby
BIRT PMC
"Michael Terk" <m_terk@yahoo.com`> wrote in message
news:c7d262f3e1b1d31c884d9b9d7e16cc31$1@www.eclipse.org...
>I have been looking for examples of how to use the addScriptableJavaObject
>method for IRunAndRenderTask class. I am using the ReportEngine (R2) and I
>want to pass an object to my report. I think I am doing the right things
>according to documentations but I keep getting an error that says:
>
> org.eclipse.birt.data.engine.core.DataException: A BIRT exception
> occurred: Error evaluating Javascript expression. Script engine error:
> TypeError: getStatus is not a function.
> Script source: null, line: 0, text:
> <compiled script>. See next exception for more information.
> Error evaluating Javascript expression. Script engine error: TypeError:
> getStatus is not a function.
> Script source: null, line: 0, text:
> <compiled script>
> at
> org.eclipse.birt.data.engine.core.DataException.wrap(DataExc eption.java:113)
> at
> org.eclipse.birt.data.engine.impl.BytecodeExpression.evaluat e(BytecodeExpression.java:53)
>
> Now getStatus (which I think is the cause of the problem) is a method in
> my class. The java code I use to send the object is as follows:
>
> Object obj = new ProcessedFilter();
> task.addScriptableJavaObject("pFilter",obj);
>
> ProcessedFilter is trivial:
>
> Public class ProcessedFilter {
> String getStatus() {return "p";}
> void setStatus(String s) {return;}
>
> }
>
> And in my JavaScript all I have is pFilter.getStatus();
>
> I think I am missing something simple but I can't find any full examples
> I can try.
>
> Thanks
> M. Terk
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.57231 seconds