2

I am using Grails 1.3.5, SQL Server 2005, iReports 3.7.6, Jasper Plugin 1.1.3. In my GSP page I have given the jasperReprt tag as:

<g:jasperReport jasper="report1" format="PDF">
<input type="hidden" name="test_id" id="test_id"/>
<input type="hidden" name="order_no" id="order_no" />   
</g:jasperReport>

For development, in Config.groovy I have specified the

jasper.dir.reports = './reports'

There are two files created in the reports folder when a new report is created and saved, i.e. report.jrxml and report.jasper.

When clicked on the PDF icon in IE or Firefox, an 500 server error is thrown and below is stack trace.

[2010-11-27 01:13:14.998] ERROR groovy.grails.web.errors.GrailsExceptionResolver Invalid byte 1 of 1-byte UTF-8 sequence. com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence. at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:684) at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:554) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1742) at

But if I delete the report1.jasper, the error is no longer thrown when PDF icon is clicked and the PDF report is shown fine.

Is this the correct way to do it?

  • My second issue is with using Sub Reports. Sub report is in the same folder as the main report. But When the report is executed from the application, below error is thrown:

    [2010-11-27 01:30:27.556] ERROR groovy.grails.web.errors.GrailsExceptionResolver Could not load object from location : ./reports\report1sub_report.jasper net.sf.jasperreports.engine.JRException: Could not load object from location : ./reports\urine_routinepatient_details_sub_report.jasper at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:262) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:301) at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:327)

It does not find the sub report. How can I fix it?

Thank you. Jay Chandran.

Edit: I have been searching during this whole time, but still could not find a proper solution. So I did some trial and error. I figured out that, deleting report1.jasper and just leaving jasper.jrxml in the report directory works just fine as I said earlier.

For the sub-report issue: It was giving error Could not load object from location : ./reports\report1sub_report.jasper For some strange reason, the main report name report was getting appended to the name sub_report.jasper and was looking for a file named report1sub_report.jasper

So I created a sub-folder under reports folder and named it report1 and updated report1.jrxml file

<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "\\sub_report.jasper"]]></subreportExpression>

I had to add the extra \\ slash even though the "SUBREPORT_DIR" parameter had \\ the slashes at the end of the path as shown below.

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["F:\\Workspace\\SpringSource2.5.0\\GrailsProjec\\reports\\report1\\"]]></defaultValueExpression>
</parameter>

Notice the \\ at the end. I don't know why it was not getting appended!

Another way would have been to just change the sub-report name from sub_report.jasper to report1sub_report.jasper!!! :)

I have tested this in production mode and it works fine. I am not sure if this is the way to do it, but all other possible solutions did not work for me.

Feedback will be very helpful.

Jay Chandran
  • 382
  • 1
  • 8
  • 20
  • thanks for your workaround for character encoding issue, i am still investigate it a proper solution – jneira Nov 04 '11 at 13:58
  • I have chosen to change the dir of compiled .jasper to c\windows\temp to avoid manual deleting of files. – jneira Nov 04 '11 at 14:04

3 Answers3

0

I assume you have a version conflict here. iReport stores JRXML files and seems to compile them automatically to .jasper. The Grails Jasper plugin picks up the compile variant and gets into trouble with it. So try to disable compiled output in ireport.

The Grails Jasper plugin 1.1.3 uses internally Jasper 3.7.4, the used ireport is 3.7.6.

Regarding the sub reports: no idea.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • thanks for your response. I have updated my question. Using the workaround mentioned in my updated question, things started to work for me. But not sure if that's the best way to do it. – Jay Chandran Nov 27 '10 at 18:25
0

The MalformedByteSequenceException is caused by a character encoding conflict. I'd suggest to use UTF-8 instead of Windows' Win-1252 (similar to ISO-8859-1) everywhere.

In Jasper's etc/ireport.conf file, change the default_options to:

default_options="-J-Dfile.encoding=UTF-8 -J-Xms24m -J-Xmx64m"

(Where Xms and Xmx are unrelated memory settings. If there are default settings with that config entry, you can overtake them, else, just leave them out.)

See this forum thread for alternative configurations.

As for the error with subreports, take a look at the backslash \ that's probably wrong.

robbbert
  • 2,183
  • 15
  • 15
  • thanks for your response. I am not sure about the Jasper's etc/ireport.conf file. I have updated my question. – Jay Chandran Nov 27 '10 at 18:17
  • i have updated C:\Archivos de programa\Jaspersoft\iReport-4.1.3\etc\ireport.conf (the correlated place for windows of config) with the file encoding option and dont work – jneira Nov 04 '11 at 14:34
0

EDIT : There is some information about two issues which maybe could help in http://grails.org/plugin/jasper#faqTab

i hope i can help with one of the issues: which one related with subreports dir. The problem is the plugin code sets SUBREPORT_DIR to the complete file path of main report, including its name. However the code honour the user provided param with the same name, so if you fill this param with whatever value except null the plugin will use it.

For example if you chain directly the jasper controller you can do:

def renderAs(data,format) {
    def reportParams=params.clone()
    reportParams["_format"]=reportParams["_format"]?:"${format.toUpperCase()}"
    reportParams["SUBREPORT_DIR"]=CH.config.jasper.dir.reports+"/"
    chain(controller:'jasper',action:'index',model:[data:[]+data],params:reportParams)
}

In your scenario an (ugly) option would be create an hidden input with name SUBREPORT_DIR and value the desired one. I would fill the paremeter in other way.

EDIT: Another annoying problem is where do we have to put the main reports and compiled subreports:

  • When you run the app with run-app they work if you put them all in a folder with the same name as CH.config.jasper.dir.reports(reportDir) in the root of the grails app.
  • But if you want to deploy a war you have to put the main reports in a folder reportDir in the root of war file and compiled subreports in WEB-INF/classes/reportDir.

I've opted to keep all files in grailsApp/reports and copy the resources in the appropiate folders in the war grails task. In my BuildConfig.groovy i've added (reportDir is "reports"):

grails.war.resources = { stagingDir,args ->
    def classpathDir="${stagingDir}/WEB-INF/classes"
    copy(toDir:"${stagingDir}/reports") {
        fileset(dir:"reports",includes:"**")
    }
    copy(toDir:"${classpathDir}/reports") {
        fileset(dir:"reports",excludes:"**.jrxml")
    }
} 

Hope it helps.

jneira
  • 944
  • 10
  • 18