I tried to run this code but it give me error like this:
2013-03-26 22:45:55,546 [pool-2-thread-1] ERROR griffon.util.GriffonExceptionHandler - Uncaught Exception
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
at org.codehaus.griffon.runtime.util.AbstractUIThreadHandler$1.run(AbstractUIThreadHandler.java:41)
Caused by: java.lang.NoClassDefFoundError: com/lowagie/text/SplitCharacter
at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:145)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:497)
at net.sf.jasperreports.engine.JasperExportManager$exportReportToPdfFile.call(Unknown Source)
at report.ReportController$_closure1_closure2.doCall(ReportController.groovy:28)
at report.ReportController$_closure1_closure2.doCall(ReportController.groovy)
... 1 more
Caused by: java.lang.ClassNotFoundException: com.lowagie.text.SplitCharacter
... 6 more
Here's the code:
--ReportController.groovy--
import net.sf.jasperreports.engine.JasperCompileManager
import net.sf.jasperreports.engine.JasperExportManager
import net.sf.jasperreports.engine.JasperFillManager
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
import net.sf.jasperreports.swing.JRViewer
class ReportController {
// these will be injected by Griffon
def model
def view
def report = {
def jasperParameter = [:]
jasperParameter.REPORT_TITLE = "Test report"
def jasperReport = JasperCompileManager.compileReport("report.jrxml")
def mapData = [:]
mapData.name = "abc"
mapData.price = 1234
def datas = [mapData]
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(datas)
def jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, dataSource)
JasperExportManager.exportReportToPdfFile(jasperPrint, "g:/sample.pdf")
JRViewer viewer = new JRViewer(jasperPrint)
viewer.setOpaque(true)
viewer.setVisible(true)
def jf = new javax.swing.JFrame ()
jf.add(viewer)
jf.setSize(800, 600)
jf.setVisible(true)
jf.setDefaultCloseOperation(EXIT_ON_CLOSE)
}
}
--ReportView.groovy--
package report
application(title: 'report',
preferredSize: [320, 240],
pack: true,
//location: [50,50],
locationByPlatform: true,
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [imageIcon('/griffon-icon-48x48.png').image,
imageIcon('/griffon-icon-32x32.png').image,
imageIcon('/griffon-icon-16x16.png').image]) {
gridLayout (cols: 1, rows: 1)
button (text: 'report', actionPerformed: controller.& report)
}
--report.jrxml-- (I put this file in /staging folder)
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test" pageWidth="800" pageHeight="1200" columnWidth="555" leftMargin="25" rightMargin="25" topMargin="30" bottomMargin="30">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[]]>
</queryString>
<pageHeader>
<band height="100">
<staticText>
<reportElement x="0" y="0" width="285" height="36"/>
<textElement>
<font size="24" isBold="true"/>
</textElement>
<text><![CDATA[Report of Testing]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="200">
<staticText>
<reportElement x="0" y="0" width="374" height="48"/>
<textElement>
<font size="18"/>
</textElement>
<text><![CDATA[If you don't see this, it didn't work blah blah blah.... ]]></text>
</staticText>
</band>
</detail>
<pageFooter>
<band height="100"/>
</pageFooter>
</jasperReport>
I don't quite know about .jrxml, i got this sample from the web, if I made a mistake please correct it.
Source: http://www.iaeronz.com/?p=562