JasperReports:如何在报告模板中调用java bean方法? [英] JasperReports: How to call a java bean method in report template?
问题描述
我将java bean集合传递给jasper报告。我为这个java bean定义了几个字段,它们在我的报告中显示得很好。
I am passing a java bean collection into a jasper report. I have several fields for this java bean defined an they are display just fine in my report.
我想知道是否有办法调用java bean的方法正在传递给这份报告???
Im wondering if there is a way to call a method of a java bean that is being passed into this report???
例如一个文本字段的表达式,类似.... ....
E.g. an expression for a text field, something like....
{current java bean}.methodToCall()
推荐答案
使用关键字 _THIS
在字段名称或描述中将使其映射到bean类本身。使用fieldDescription标签更好,因为它允许您使用多个bean执行此操作。
Using the keyword _THIS
in a field name or description will make it map to the bean class itself. Using the fieldDescription tag is better as it allows you to do this with multiple beans.
例如:
<field name="customBean" class="com.example.customBean">
<fieldDescription>_THIS</fieldDescription>
</field>
然后你可以在这样的表达式中调用方法:
Then you can call methods in an expression like this:
<textFieldExpression>$F{customBean}.someMethod()</textFieldExpression>
这篇关于JasperReports:如何在报告模板中调用java bean方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!