JasperReports: How to call a java bean method in report template?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 16:36:46

问题


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.

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()

回答1:


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.

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>


来源:https://stackoverflow.com/questions/6638569/jasperreports-how-to-call-a-java-bean-method-in-report-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!