We have faced the problem of displaying the "Page x of y" in the summary band of our reports. We have started implementing this using a post from the jasper forum: http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=18975 . This was not enough however because the pageCount variable expression would not be evaluated when a summary page was encountered, so we overcome this by using a initial value expression like that : ($V{pageCount} == null) ? 0 : $V{pageCount} + 1.
The $V{pageCount} is null the first time the variable is initialised, so the pageCount variable is set to 0. This did not matter because the value of the variable would be set again according to the pageCount variable expression to be equal to the value of the PAGE_NUMBER variable.
The second case is really interesting, because when a summary page is encountered the pageCount variable value is not the one defined in the pageCount variable expression, but the one defined in the initial value expression. Now, the test $V{pageCount} == null returns false and the pageCount value is set to $V{pageCount} + 1 which is printed in the footer of the page. Next, if there is another summary page is process is continued, printing the correct page in the footer.
Monday, March 14, 2011
Monday, February 14, 2011
I have ran into a problem when filling Jasper Reports that contain sub-reports. Jasper couldn't find by itself the sub-reports, although they were located into the same directory with the main report.
One way to solve this was to set the REPORT_FILE_RESOLVER parameter to the directory that contains the sub-reports, as describe here: http://forums.devshed.com/java-help-9/relative-path-for-subreport-in-jasperreport-309313.html
This created a problem because my code was packaged into a jar file that was part of an ear file and the approach described above wouldn't work, because I couldn't create a File object representing the sub-report directory to pass to the SimpleResolver class.
The best way I could find for doing this is to set the SUBREPORT_DIR parameter on the main report like this : "subreport_dir/".
One way to solve this was to set the REPORT_FILE_RESOLVER parameter to the directory that contains the sub-reports, as describe here: http://forums.devshed.com/java-help-9/relative-path-for-subreport-in-jasperreport-309313.html
This created a problem because my code was packaged into a jar file that was part of an ear file and the approach described above wouldn't work, because I couldn't create a File object representing the sub-report directory to pass to the SimpleResolver class.
The best way I could find for doing this is to set the SUBREPORT_DIR parameter on the main report like this : "subreport_dir/".
Friday, February 4, 2011
Using Jasper templates inside a maven Java project
I have came across an issue with using compiled jasper templates inside a maven Java project. If I placed the jasper template inside the test resources for a project(src/test/resources) and then created a jasper report using that template in a test case everything worked smoothly. If however I moved the template in the project resources directory(src/main/java) and then tried to run the same test case I would get an
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jasper</nonFilteredFileExtension> </nonFilteredFileExtensions>
java.io.StreamCorruptedException:invalid stream header: EFBFBDEF exception.
It turns out this happens because I had the resources filtering enabled in my project and Maven filtered the jasper file, producing in the target folder a file that was different than what I had in my resource folder. Hence, the stream corrupted exception. The solution to solve this is to configure the maven resources plug-in to exclude the .jasper file from filtering like this:<nonFilteredFileExtensions>
<nonFilteredFileExtension>jasper</nonFilteredFileExtension> </nonFilteredFileExtensions>
Subscribe to:
Posts (Atom)