JasperReports:如何在报告模板中调用 java bean 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6638569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JasperReports: How to call a java bean method in report template?
提问by tinny
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 集合传递到一个 jasper 报告中。我为这个 java bean 定义了几个字段,它们在我的报告中显示得很好。
Im wondering if there is a way to call a method of a java bean that is being passed into this report???
我想知道是否有办法调用传递到此报告中的 java bean 的方法???
E.g. an expression for a text field, something like....
例如,文本字段的表达式,例如....
{current java bean}.methodToCall()
回答by GenericJon
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.
_THIS
在字段名称或描述中使用关键字将使其映射到 bean 类本身。使用 fieldDescription 标记更好,因为它允许您使用多个 bean 来执行此操作。
For example:
例如:
<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>