GithubHelp home page GithubHelp logo

yakworks / grails-jasper-reports Goto Github PK

View Code? Open in Web Editor NEW
2.0 8.0 1.0 643 KB

Grails plugin to add support for exporting jasper reports and incorporates Spring's MVC architecture

License: Apache License 2.0

Groovy 51.28% Java 6.08% HTML 42.64%
jasperreports grails grails-plugin grails3 spring-mvc springframework

grails-jasper-reports's Introduction

Moved project for Grails 5 and Groovy 3 compatibility. go to https://github.com/yakworks/spring-grails-kit

CircleCI 9ci

see branch and versions 3.0.x - Works with Grails 3.2.x

Install for grails 3.3.x

compile "org.grails.plugins:jasper-reports:3.2.0"

Table of Contents

Summary

Jasper reports plugin integrates jasper reports library with grails and makes it easy to generate and render reports. Plugin also configures jasper spring mvc view resolver which makes it possible to render views as reports easily from controllers.

Quick Start

class DemoController {
	def index() {
		render view: 'demo.jrxml', model: [name: 'Jeff Beck', instrument: 'Guitar']
	}
}

that looks like this:

<html>
<body>
	Name: ${name} <br/>
	Instrument: ${instrument}<br/>
</body>
</html>

Use your browser to navigate to http://localhost:8080/yourApp/demo

Done!

Usage

Plugin configures a spring mvc view resolver which handles .jasper and .jrxml files. This makes it extremely easy to generate reports. the .jrxl file can be put inside grails-app/views directory just like a gsp view and it will be rendered as jasper report as shown in quick start example above.

It is also possible to render reports programmatically using JasperService as shown in Services section below.

Services

JasperService
JasperService provides methods to programmatically generate and render reports.

Example

class ReportController {

import yakworks.jasper.JasperService
import yakworks.jasper.spring.JasperReportDef
import yakworks.reports.ReportFormat


   def generate(String name) {
        JasperService jasperService
   
        List reportData = [] //prepare list of maps which will be feed to jasper report as data.
            
        JasperReportDef opts = new JasperReportDef(
                name: name, //the name of jrxml or compiled .jasper file
                fileFormat: ReportFormat.PDF,
                parameters: [param1:value1, param2:value2], //pass whatever parameter needed.
                reportData: reportData
        )
   
   	    ByteArrayOutputStream out = jasperService.generateReport(opts)
   		//do some thing with ByteArrayOutputStream, write to file or stream to browser etc.
   }

}

Configuration

Configuring ViewResourceLocator to add extra directories as report files location. Plugin configures an instance of ViewResourceLocator as spring bean with name jasperViewResourceLocator Which is used internally to locate jasper report template files. So every thing explained in view tools plugin docs Applies to jasperViewResourceLocator.

Here is an example of how to use an external directory to store jasper report template files.

grails-app/conf/spring/resources.groovy

jasperViewResourceLocator(grails.plugin.viewtools.ViewResourceLocator) { bean ->
   
    searchPaths = [
        "file:/someLoc/my-templates/" //the directory which contains the jasper templates
    ] 

   searchBinaryPlugins = true

   if (!application.warDeployed) { // <- grails2
		grailsViewPaths = ["/grails-app/views"]
		webInfPrefix = ""
    }

}

History

grails-jasper-reports's People

Contributors

9cibot avatar basejump avatar ken-roberts avatar snimavat avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jdaugherty

grails-jasper-reports's Issues

Fix ignore test from DynamicReportsServiceSpec

The test started failing with 3.3.9
The issue seems to have some thing to do with the metaclass
Bills.customer field is not being recognized as Association by gorm.

That is because the ClassPropertyFetcher.getMetaProperties does not have the Customer in returned list.

It has some thing to do with groovy meta class and CachedClass

for Bills
theMetaClass.getProperties() does not have a property in the list returned โ€” even though it exists in class. But Doing theMetaClass.theClass.getDeclaredFields() contains the field though.

Can't start JasperService

Using Grails 3.3.4 and I put in the plugin dependency:

compile 'org.grails.plugins:jasper-reports:3.1.1'

And on startup I got:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class nine.jasper.JasperService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 23 common frames omitted
Caused by: org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class nine.jasper.JasperService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at grails.core.ArtefactHandlerAdapter.newArtefactClass(ArtefactHandlerAdapter.java:170)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:825)
at grails.core.DefaultGrailsApplication.addOverridableArtefact(DefaultGrailsApplication.java:815)
at grails.core.DefaultGrailsApplication.addOverridableArtefact(DefaultGrailsApplication.java:800)
at org.grails.plugins.AbstractGrailsPluginManager.registerProvidedArtefacts(AbstractGrailsPluginManager.java:310)
[snip]
Caused by: java.lang.NullPointerException: null
at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1337)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1197)
at java.beans.Introspector.getBeanInfo(Introspector.java:426)
at java.beans.Introspector.getBeanInfo(Introspector.java:173)
at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3328)
at java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3326)

I'm ok downgrading the Grails version, I would just like to know what you have tested it with.

Always Empty PDF Generated

Hi,

Im trying to integrate the plugin with grails 4 but it's just always generating an empty PDF:

    def reportDef = new JasperReportDef(name:'test.jrxml', fileFormat: ReportFormat.PDF, reportData: [])
    ByteArrayOutputStream output = jasperService.generateReport(reportDef)

If I try without the plugin:

JasperReport jasperReport = JasperCompileManager.compileReport("test.jrxml")
def jasperPrint = JasperFillManager.fillReport(jasperReport, null, new JREmptyDataSource())
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()
JasperExportManager.exportReportToPdfStream(jasperPrint, byteArrayOutputStream)

it's working, did I miss something?

GRAILS 4.04 JASPER PLUGIN FAILED

compile 'org.grails.plugins:jasper:2.1.0'
compile 'org.grails.plugins:jasper-reports:3.2.0'

The above dependencies failed to work in Grails 4.04, any solution for this problem?

Example Request: POST json as a parameter to a report

Hi 9ci Team,

First, thanks for creating this plug-in for Grails!

I would like to request a code example where json data is POSTed to the controller and passed to the report as an inputControl for use as the data source for the report. The idea would be an application, say an ERP system, would pass a large data set (say 1000 invoices) as json to the controller via a POST request, and the invoice.jrxml report would render that data as a PDF of the batch of invoices.

Thanks again!

-Tim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.