我在我的应用程序中使用 Grails Jasper 报告插件。我试图将一组 Expandos 绑定(bind)到我的报告模板。
我的 Expando 构建如下
def calendarTask = new Expando()
calendarTask.title = task.name
calendarTask.date = new Date()
data.add(calendarTask)
然后我在我的 Controller 中绑定(bind)集合
chain(controller:'jasper', action:'index', model:[data:data], params:params)
在我的报告中,我的报告模板中定义了一个名为“标题”(类型字符串)的字段。当我尝试运行此报告时,出现以下异常。您可以将 Groovy Expando 集合绑定(bind)到 jasper 报告吗?
java.lang.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)
最佳答案
我写了一个快速测试脚本,它给出了同样的错误
@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' )
所以它看起来像
common-beanutils
和 Expando
一起玩不好...但是,如果您改变使用
Expando
只使用普通的Map
, beanutils 调用有效,所以您可以尝试将代码更改为:def calendarTask = [
title : task.name,
date : new Date(),
]
data.add(calendarTask)
关于grails - 是否可以将 Groovy Expandos 的集合绑定(bind)到碧 Jade 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6580015/