Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 316173

Summary: viewtime-value-of does not work with pdf and page variables.
Product: z_Archived Reporter: Jason Weathersby <jasonweathersby>
Component: BIRTAssignee: Jun Ouyang <jouyang>
Status: VERIFIED FIXED QA Contact: Xiaodan Wang <xwang>
Severity: normal    
Priority: P3 CC: bluesoldier, wenfeng.fwd, wyan
Version: 2.6.0Flags: wenfeng.fwd: pmc_approved+
Target Milestone: 2.6.0 RC4   
Hardware: PC   
OS: Windows 7   
Whiteboard: Need-Auto
Attachments:
Description Flags
example report
none
example none

Description Jason Weathersby CLA 2010-06-08 12:46:00 EDT
See attached report.  Run in viewer and check page 2 of shipped category.  It works in HTML.  Export to PDF and the incorrect value is displayed.
Comment 1 Jason Weathersby CLA 2010-06-08 12:47:36 EDT
Created attachment 171428 [details]
example report

look at the text element with this expression:
<viewtime-value-of>
vars["GROUP_PAGE"]
</viewtime-value-of>
Comment 2 Wenfeng Li CLA 2010-06-08 13:05:15 EDT
PLease evaluate the risk of fixing this in 2.6 RC4, if too large a change, please consider 2.6.1.
Comment 3 Wei Yan CLA 2010-06-08 13:05:35 EDT
Page break scripts are invoked on the run time, it means once the run time pagination is created, the page variable value won't be changed anymore.

In your design, the report uses the auto layout. In this case, the PDF pagination may not equal to the HTML pagination due to the limitation of the master page size.

You can change it to fix layout and retry.
Comment 4 Wei Yan CLA 2010-06-08 13:10:00 EDT
You can also change the page style to "Fit to Whole Page" in the PDF export dialog, so the PDF uses the same pagination with HTML.

As it is not a bug, I set it to INVALID.
Comment 5 Jason Weathersby CLA 2010-06-08 13:14:25 EDT
I can't change to fixed layout as the viewer throws an exception on the pageend script.  I am not certain why.

I do not know what you mean by:
Page break scripts are invoked on the run time, it means once the run time
pagination is created, the page variable value won't be changed anymore.
Comment 6 Wei Yan CLA 2010-06-08 13:21:41 EDT
For auto-layout, the PDF pagination is not equal to the HTML pagination. The HTML pagination is done in the run time with the page script executing.

To render the HTML page to PDF, the user can choose if one HTML page should be outputted to one or multiple pages if the page content is larger than the master page size. If the user prefers multiple pages which is the "auto" page style in PDF export dialog, the HTML page is re-paginated based on the page size. In this case, the onPageScript won't be executed. You may see that the page variable's value is not correct for the new created pages.

If the user prefers one page which is the "Fit to Whole page" mode, each HTML page is outputted to one PDF page. In this mode, as the PDF pagination is consistent with the HTML pagination, the result is correct.

Anyway, to resolve this issue, you can either choose the fix-layout or use the "fit to whole page" output mode as a workaround.
Comment 7 Wenfeng Li CLA 2010-06-08 13:25:25 EDT
Need to fix the exception in the pageend script when using fix-layout?

Jason, can you copy the exception message into comments?
Comment 8 Wei Yan CLA 2010-06-08 13:27:57 EDT
re-open this issue as there is an class cast exception in the onPageEnd:

org.eclipse.birt.report.engine.ir.SimpleMasterPageDesign cannot be cast to
org.eclipse.birt.report.engine.ir.ReportItemDesign
(/report/page-setup/simple-master-page[@id="2"]/method[@name="onPageEnd"]#1)
    at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1654)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:175)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
    at
org.mozilla.javascript.gen.c20._c0(/report/page-setup/simple-master-page[@id="2"]/method[@name="onPageEnd"]:1)
    at
org.mozilla.javascript.gen.c20.call(/report/page-setup/simple-master-page[@id="2"]/method[@name="onPageEnd"])
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
    at
org.mozilla.javascript.gen.c20.call(/report/page-setup/simple-master-page[@id="2"]/method[@name="onPageEnd"])
    at
org.mozilla.javascript.gen.c20.exec(/report/page-setup/simple-master-page[@id="2"]/method[@name="onPageEnd"])
    at
org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:282)
    ... 34 more
Caused by: java.lang.ClassCastException:
org.eclipse.birt.report.engine.ir.SimpleMasterPageDesign cannot be cast to
org.eclipse.birt.report.engine.ir.ReportItemDesign
    at
org.eclipse.birt.report.engine.script.internal.instance.PageInstance.getInstancesByElementName(PageInstance.java:79)
    at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
    ... 43 more
Comment 9 Jason Weathersby CLA 2010-06-08 13:40:30 EDT
Created attachment 171433 [details]
example

It is complaining when using either:
    //var groups = this.getInstancesByElementName("GROUP_STATUS");


    //var groups = this.getInstancesByElementId(73);

So I modified the report to use another method and it let me set fixed.  Please run this in the viewer and then export to pdf to see the issue.
Comment 10 Jun Ouyang CLA 2010-06-08 23:16:50 EDT
Fix the class cast exception.
1. Check if IContent.getGenerateBy() returns ReportElementDesign.
2. Cast to ReportElementDesign instead of ReportItemDesign.
Comment 11 Xiaodan Wang CLA 2010-06-09 06:28:51 EDT
1. When export to PDF and fit to whole page, the page variable works correctly.
2. No exception  on the pageend script.

Verified in build (2.6.0.v20100609-1747).