Home » Archived » BIRT » Embedded Report - JavaScript Error(Embedded Report - JavaScript Error)
Embedded Report - JavaScript Error [message #676899] |
Mon, 06 June 2011 18:01  |
Eclipse User |
|
|
|
I'm running into a strange problem with JavaScript. We have a report that is embedded in a J2EE application, running on WebSphere 6.1 and BIRT 3.2.2.
The report generates PDF documents on request, the docs are sent to an FTP server.
In the report design's initialize event, we define two global methods that are used to determine the MasterPage property for report elements.
function willFitOnFirstPage ( target ) {
return ( reportContext.getAppContext().get("lineCount") < target );
}
// make willFitOnFirstPage() globally available
reportContext.setPersistentGlobalVariable("willFitOnFirstPage", willFitOnFirstPage);
function assignMasterPage ( element, target ) {
if ( reportContext.getAppContext().get("showInsertionBarcode").toLowerCase().indexOf("y") == -1 ) {
element.getStyle().masterPage = "NoBarcodeMasterPage";
}
else if ( willFitOnFirstPage(target) ) {
element.getStyle().masterPage = "FirstMasterPage";
}
else {
element.getStyle().masterPage = "FollowingMasterPage";
}
}
// make assignMasterPage() globally available
reportContext.setPersistentGlobalVariable("assignMasterPage", assignMasterPage);
The problem is this: when the application/server is started, everything works fine. Then, after a week or so, we start getting the following error:
org.eclipse.birt.core.exception.CoreException: There are errors evaluating script "assignMasterPage(this, 141);
":
TypeError: Cannot find function toLowerCase. (/report/method[@name="initialize"]#16).
So it seems like somehow the JavaScript engine is getting corrupted? Or the report design? This problem happens on two different servers.
Any thoughts, insight or suggestions would be much appreciated!
Steve
|
|
|
Re: Embedded Report - JavaScript Error [message #677193 is a reply to message #676899] |
Tue, 07 June 2011 13:59   |
Eclipse User |
|
|
|
Are you cetain this is always set to a string?
reportContext.getAppContext().get("showInsertionBarcode")
You may want to toString() the object before calling the toLowerCase
Also you may want to put importPackage(Packages.java.lang) at the top of
the beforeFactory.
Jason
On 6/6/2011 6:01 PM, forums-noreply@eclipse.org wrote:
> I'm running into a strange problem with JavaScript. We have a report
> that is embedded in a J2EE application, running on WebSphere 6.1 and
> BIRT 3.2.2.
>
> The report generates PDF documents on request, the docs are sent to an
> FTP server.
>
> In the report design's initialize event, we define two global methods
> that are used to determine the MasterPage property for report elements.
>
> function willFitOnFirstPage ( target ) {
> return ( reportContext.getAppContext().get("lineCount") < target );
> }
> // make willFitOnFirstPage() globally available
> reportContext.setPersistentGlobalVariable("willFitOnFirstPage",
> willFitOnFirstPage);
>
> function assignMasterPage ( element, target ) {
> if (
> reportContext.getAppContext().get("showInsertionBarcode").toLowerCase().indexOf("y")
> == -1 ) { element.getStyle().masterPage = "NoBarcodeMasterPage"; }
> else if ( willFitOnFirstPage(target) ) { element.getStyle().masterPage =
> "FirstMasterPage";
> }
> else {
> element.getStyle().masterPage = "FollowingMasterPage"; }
> }
> // make assignMasterPage() globally available
> reportContext.setPersistentGlobalVariable("assignMasterPage",
> assignMasterPage);
>
> The problem is this: when the application/server is started, everything
> works fine. Then, after a week or so, we start getting the following error:
>
> org.eclipse.birt.core.exception.CoreException: There are errors
> evaluating script "assignMasterPage(this, 141);
> ":
> TypeError: Cannot find function toLowerCase.
> (/report/method[@name="initialize"]#16).
>
>
> So it seems like somehow the JavaScript engine is getting corrupted? Or
> the report design? This problem happens on two different servers.
>
> Any thoughts, insight or suggestions would be much appreciated!
> Steve
>
|
|
| | | | |
Re: Embedded Report - JavaScript Error [message #682340 is a reply to message #682207] |
Fri, 10 June 2011 17:29   |
Eclipse User |
|
|
|
We are holding onto the report engine and the report design objects between execution. A fresh new task object is used in every run.
We've narrowed the issue down, the problem is occurring in the Java code that is preparing the task for execution. Basically, we put one value (a string) into the appcontext, but when we check that value, it's coming back as the ExecutionContext object.
Here's the core of the Java code, I've flagged the part where the error occurs.
private static IReportEngine engine;
private static ReportDesignCache designCache;
private void executeReport(Invoice invoice, boolean isRemote) throws Exception {
if (engine == null) {
engine = BirtEngine.getBirtEngine();
}
if (designCache == null) {
designCache = new ReportDesignCache(engine);
}
String countryCode = "US";
countryCode = invoice.getHeader().getCountryCode();
String warehouseCode = invoice.getHeader().getWarehouseCode();
ReportProperties config = new ReportProperties(warehouseCode, countryCode);
IReportRunnable design = designCache.get(config.getDesignFileName());
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
if (isRemote) {
task.setRenderOption(getRenderOptionRemote(config));
}
else {
task.setRenderOption(getRenderOptionInteractive(config));
}
ReportHeader h = new ReportHeader();
h.load(invoice.getHeader());
ReportBody b = new ReportBody();
b.load(invoice);
ReportTotals t = new ReportTotals();
t.load(invoice);
ReportLayout l = new ReportLayout();
l.load(config, invoice);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("ReportHeader", h);
parameters.put("ReportDetails", b);
parameters.put("ReportTotals", t);
parameters.put("ReportLayout", l);
// *** enabling following two lines seems to prevent error condition ***
// putAppContext(task, "sacrifice1", "goat");
// putAppContext(task, "sacrifice2", "chicken");
// *** error condition originates in this loop ***
for (String key: config.getParameters().keySet()) {
log.logWarn("Config value for key:" + key + ", value:" + config.getParameter(key) + ":");
putAppContext(task, key, config.getParameter(key));
}
log.logWarn("AppContext value for showInsertionBarcode: '" + task.getAppContext().get("showInsertionBarcode") + "'");
putAppContext(task, "PrintOrderTotals", invoice.getHeader().getPrintOrderTotal());
log.logWarn("AppContext value for showInsertionBarcode(2): '" + task.getAppContext().get("showInsertionBarcode") + "'");
Long lineCount = invoice.getDetailSectionHeight();
putAppContext(task, "lineCount", lineCount.toString());
task.setParameterValues(parameters);
task.run();
task.close();
log.logWarn("AppContext value for showInsertionBarcode(3): '" + task.getAppContext().get("showInsertionBarcode") + "'");
if (isRemote) {
cbb.getOutputStream().close();
DistributeReportProcess dist = new DistributeReportProcess();
dist.setDrop(drop);
String fileName = generateFileName(config.isPostscript(), invoice);
dist.writeFile(fileName, cbb.getInputStream());
}
}
@SuppressWarnings("unchecked")
private void putAppContext(IRunAndRenderTask task, String id, Object value) {
task.getAppContext().put(id, value);
}
Here's a section of the log, showing the issue:
AppContext value key:showInsertionBarcode, value:YES:
AppContext value key:design, value:TestInvoicePackingList.rptdesign:
AppContext value key:showSmartLabel, value:YES:
AppContext value key:format, value:pdf:
AppContext value for showInsertionBarcode: 'org.eclipse.birt.report.engine.executor.ExecutionContext@3c743c74'
AppContext value for showInsertionBarcode(2): 'org.eclipse.birt.report.engine.executor.ExecutionContext@3c743c74'
AppContext value for showInsertionBarcode(3): 'org.eclipse.birt.report.engine.executor.ExecutionContext@3c743c74'
|
|
|
Re: Embedded Report - JavaScript Error [message #682425 is a reply to message #682340] |
Fri, 10 June 2011 23:44  |
Eclipse User |
|
|
|
When you create the task can you try creating a new hashmap add any
values you want to the map and then set the appcontext for the task?
The Birt Viewer does it like:
Map context = BirtUtility.getAppContext( request );
runAndRenderTask.setAppContext( context );
//from BirtUtility
public static Map getAppContext( HttpServletRequest request )
{
HashMap context = new HashMap( );
Boolean isDesigner = Boolean.valueOf( ParameterAccessor.isDesigner( ) );
context.put( "org.eclipse.birt.data.engine.dataset.cache.option",
//$NON-NLS-1$
isDesigner );
context.put( EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST,
request );
// Client DPI setting
context.put( EngineConstants.APPCONTEXT_CHART_RESOLUTION,
ParameterAccessor.getDpi( request ) );
// Max cube fetch levels
int maxCubeRowLevels = ParameterAccessor.getMaxCubeRowLevels( request );
if ( maxCubeRowLevels >= 0 )
context.put( DataEngine.CUBECUSROR_FETCH_LIMIT_ON_ROW_EDGE,
Integer.valueOf( maxCubeRowLevels ) );
int maxCubeColumnLevels = ParameterAccessor.getMaxCubeColumnLevels(
request );
if ( maxCubeColumnLevels >= 0 )
context.put( DataEngine.CUBECURSOR_FETCH_LIMIT_ON_COLUMN_EDGE,
Integer.valueOf( maxCubeColumnLevels ) );
// Cube memory size
int cubeMemorySize = ParameterAccessor.getCubeMemorySize( request );
if ( cubeMemorySize >= 0 )
context.put( DataEngine.IN_MEMORY_CUBE_SIZE,
Integer.valueOf( cubeMemorySize ) );
// add resource path to app context
context.put( IBirtConstants.APPCONTEXT_BIRT_RESOURCE_PATH,
ParameterAccessor.getResourceFolder( request ) );
// Push user-defined application context
ParameterAccessor.pushAppContext( context, request );
if ( isDesigner.booleanValue( ) )
{
String appContextName = ParameterAccessor.getAppContextName( request );
getAppContextFromExtension( appContextName, context );
}
return context;
}
Jason
On 6/10/2011 5:29 PM, forums-noreply@eclipse.org wrote:
> We are holding onto the report engine and the report design objects
> between execution. A fresh new task object is used in every run.
>
> We've narrowed the issue down, the problem is occurring in the Java code
> that is preparing the task for execution. Basically, we put one value (a
> string) into the appcontext, but when we check that value, it's coming
> back as the ExecutionContext object.
>
> Here's the core of the Java code, I've flagged the part where the error
> occurs.
>
> private static IReportEngine engine;
> private static ReportDesignCache designCache;
>
> private void executeReport(Invoice invoice, boolean isRemote) throws
> Exception {
> if (engine == null) {
> engine = BirtEngine.getBirtEngine();
> }
> if (designCache == null) {
> designCache = new ReportDesignCache(engine);
> }
>
> String countryCode = "US";
> countryCode = invoice.getHeader().getCountryCode();
> String warehouseCode = invoice.getHeader().getWarehouseCode();
>
> ReportProperties config = new ReportProperties(warehouseCode, countryCode);
> IReportRunnable design = designCache.get(config.getDesignFileName());
> IRunAndRenderTask task = engine.createRunAndRenderTask(design);
>
> if (isRemote) {
> task.setRenderOption(getRenderOptionRemote(config));
> }
> else {
> task.setRenderOption(getRenderOptionInteractive(config));
> }
>
> ReportHeader h = new ReportHeader();
> h.load(invoice.getHeader());
>
> ReportBody b = new ReportBody();
> b.load(invoice);
>
> ReportTotals t = new ReportTotals();
> t.load(invoice);
>
> ReportLayout l = new ReportLayout();
> l.load(config, invoice);
>
> Map<String, Object> parameters = new HashMap<String, Object>();
> parameters.put("ReportHeader", h);
> parameters.put("ReportDetails", b);
> parameters.put("ReportTotals", t);
> parameters.put("ReportLayout", l);
>
> // *** enabling following two lines seems to prevent error condition ***
> // putAppContext(task, "sacrifice1", "goat");
> // putAppContext(task, "sacrifice2", "chicken");
>
> // *** error condition originates in this loop ***
> for (String key: config.getParameters().keySet()) {
> log.logWarn("Config value for key:" + key + ", value:" +
> config.getParameter(key) + ":");
> putAppContext(task, key, config.getParameter(key));
> }
> log.logWarn("AppContext value for showInsertionBarcode: '" +
> task.getAppContext().get("showInsertionBarcode") + "'");
>
> putAppContext(task, "PrintOrderTotals",
> invoice.getHeader().getPrintOrderTotal());
> log.logWarn("AppContext value for showInsertionBarcode(2): '" +
> task.getAppContext().get("showInsertionBarcode") + "'");
>
> Long lineCount = invoice.getDetailSectionHeight();
> putAppContext(task, "lineCount", lineCount.toString());
>
> task.setParameterValues(parameters);
>
> task.run();
> task.close();
> log.logWarn("AppContext value for showInsertionBarcode(3): '" +
> task.getAppContext().get("showInsertionBarcode") + "'");
>
> if (isRemote) {
> cbb.getOutputStream().close();
> DistributeReportProcess dist = new DistributeReportProcess();
> dist.setDrop(drop);
> String fileName = generateFileName(config.isPostscript(), invoice);
> dist.writeFile(fileName, cbb.getInputStream());
> }
> }
>
> @SuppressWarnings("unchecked")
> private void putAppContext(IRunAndRenderTask task, String id, Object
> value) {
> task.getAppContext().put(id, value);
> }
>
> Here's a section of the log, showing the issue:
>
> AppContext value key:showInsertionBarcode, value:YES:
> AppContext value key:design, value:TestInvoicePackingList.rptdesign:
> AppContext value key:showSmartLabel, value:YES:
> AppContext value key:format, value:pdf:
> AppContext value for showInsertionBarcode:
> 'org.eclipse.birt.report.engine.executor.ExecutionContext@3c743c74'
> AppContext value for showInsertionBarcode(2):
> 'org.eclipse.birt.report.engine.executor.ExecutionContext@3c743c74'
> AppContext value for showInsertionBarcode(3):
> 'org.eclipse.birt.report.engine.executor.ExecutionContext@3c743c74'
|
|
|
Goto Forum:
Current Time: Tue Jul 22 18:55:34 EDT 2025
Powered by FUDForum. Page generated in 0.92703 seconds
|