如何在jasperreports中访问数据源的根元素 [英] How to access the root element of the datasource in jasperreports

查看:77
本文介绍了如何在jasperreports中访问数据源的根元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由MyJavaBean集合支持的报告。

I have a report backed by a collection of MyJavaBean.

在本报告中,我(当然)可以获取MyJavaBean的属性,在Fields中声明它们并使用它在详细信息区域,到目前为止一直很好。

In this report I (of course) can get the properties of MyJavaBean declaring them in the Fields and using it on the details band, so far so good.

现在我希望能够将此MyJavaBean作为子报表的参数传递。看来我希望能够传递javabean本身,而不是它的一个属性。

Now I want to be able to pass this MyJavaBean as a parameter of a subreport. Look that I want to be able to pass the javabean itself, not one of its propertys.

如何在detais乐队中引用我的收藏中的一个元素?

How can I make reference to one element of my collection in the detais band?

推荐答案

引用bean



声明引用bean的字段bean本身而不是其中一个属性,将字段描述设置为关键字 _THIS

<field name="myJavaBean" class="com.your.package.MyJavaBean">
    <fieldDescription>_THIS</fieldDescription>
</field>

然后,您可以将其作为子报表参数传递,就像任何其他字段一样。

You can then pass this as a subreport parameter like any other field.

<subreportParameter name="myJavaBean">
    <subreportParameterExpression>
        <![CDATA[$F{myJavaBean}]]>
    </subreportParameterExpression>
</subreportParameter>

可以通常的方式调用bean中的方法,即: $ F {myJavaBean} .someMethod()

Methods in the bean can be called in the normal way, i.e: $F{myJavaBean}.someMethod()

根据你在这里做的事情,可能会更困难。如果只想查看单个元素的详细信息,请将波段上的 printWhenExpression 设置为所需元素的键。但是,如果您希望某些报表元素引用集合中的一个对象,而其余的带引用另一个对象,那么在详细信息区域中嵌套另一个子报表可能会更好。

Depending on what you are doing here it could be more difficult. If you want to only see the detail for the single element, set the printWhenExpression on the band to the key of the element you want. However, if you want to have some report elements reference one object in the collection while the rest of the band references another, it would probably be better for you to nest another subreport within the detail band.

这篇关于如何在jasperreports中访问数据源的根元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆