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.

4

3 回答 3

0

我假设您在这里有版本冲突。iReport 存储 JRXML 文件,并且似乎自动将它们编译为 .jasper。Grails Jasper 插件选择了编译变体并遇到了麻烦。所以尝试禁用 ireport 中的编译输出。

Grails Jasper 插件 1.1.3 内部使用 Jasper 3.7.4,使用的 ireport 是 3.7.6。

关于子报告:不知道。

于 2010-11-27T16:24:09.877 回答
0

编辑:有一些关于两个问题的信息可能有助于 http://grails.org/plugin/jasper#faqTab

我希望我能帮助解决其中一个问题:哪一个与子报表目录有关。问题是插件代码将 SUBREPORT_DIR 设置为主报告的完整文件路径,包括其名称。但是,代码尊重用户提供的具有相同名称的参数,因此如果您使用除 null 之外的任何值填充此参数,插件将使用它。

例如,如果您直接链接 jasper 控制器,您可以执行以下操作:

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)
}

在您的场景中,一个(丑陋的)选项将创建一个名为 SUBREPORT_DIR 的隐藏输入并设置所需的值。我会以其他方式填写参数。

编辑:另一个烦人的问题是我们必须把主要报告和编译的子报告放在哪里:

  • 当您使用 run-app 运行应用程序时,如果您将它们全部放在与 grails 应用程序根目录中的 CH.config.jasper.dir.reports(reportDir) 同名的文件夹中,它们就可以工作。
  • 但是如果你想部署一个战争,你必须把主要的报告放在战争文件根目录的reportDir文件夹中,在WEB-INF/classes/reportDir中编译子报告。

我选择将所有文件保存在 grailsApp/reports 中,并将资源复制到 war grails 任务的相应文件夹中。在我的 BuildConfig.groovy 中,我添加了(reportDir 是“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")
    }
} 

希望能帮助到你。

于 2011-11-04T13:53:38.323 回答
0

MalformedByteSequenceException是由字符编码冲突引起的。我建议在任何地方都使用 UTF-8 而不是 Windows 的 Win-1252(类似于 ISO-8859-1)。

在 Jasper 的etc/ireport.conf文件中,将其更改default_options为:

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

(哪里XmsXmx是不相关的内存设置。如果该配置条目有默认设置,您可以超越它们,否则,只需将它们排除在外。)

有关替代配置,请参阅此论坛主题。

至于子报表的错误,看看\可能是错误的反斜杠。

于 2010-11-27T17:43:37.470 回答