开发者

Is it possible to bind a collection of Groovy Expandos to a jasper report?

I'm using the Grails Jasper report plugin in my application. Im trying to bind a collection of Expandos to my report template.

My Expando is built as follows

def calendarTask = new Expando() 
calendarTask.title = task.name 
calendarTask.date = new Date() 
data.add(calendarTask)

I then bind the collection in my controller

chain(controller:'jasper', action:'index', model:[data:data], params:params)

In my report I have a field called "title" (type string) defined in my report template. When I try and run this report I get the exception below. Can you bind Groovy Expando collection to jasper reports?

java.l开发者_运维问答ang.NoSuchMethodException: Unknown property 'title' on class 'class groovy.util.Expando'

at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1313)

at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:762)

at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:837)


I wrote a quick test script, and it gave the same error

@Grapes(
    @Grab(group='commons-beanutils', module='commons-beanutils', version='1.8.3')
)
import org.apache.commons.beanutils.PropertyUtilsBean

def calendarTask = new Expando() 
calendarTask.title = { -> 'tim' }
calendarTask.date = { -> new Date() }

println new PropertyUtilsBean().getProperty( calendarTask, 'title' )

So it looks like common-beanutils and Expando don't play well together...

However, if you change from using Expando to just using a plain Map, the beanutils call works, so could you try changing your code to:

def calendarTask = [
  title : task.name,
  date  : new Date(),
]
data.add(calendarTask)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜