问题描述
我有这个对象结构,可以像mi jasper报告中的Java Bean一样使用
I have this object structure, to use like Java Bean in mi jasper report,
public class Person{
private String name;
private String lastname;
private List<Job> jobs;
}
public class Job{
private String jobName;
private String companyName;
private List<Reponsability> responsabilities;
}
所有具有相应setters
和getters
当我在碧玉报告中创建一个列表时,我以此方式定义工作列表" JRDataSource expression
:
When I create a list into jasper report I define the "job list" JRDataSource expression
this way:
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{jobs})
现在,我想在工作列表" 上创建另一个列表,职责列表" ,问题是:
Now I want to create another list, "responsibilities list" on the "job list", the question is:
如何定义数据源以获取相应的作业以传递到JRDataSource Expression
?
How can I define the data source to get the corresponding job to pass into the JRDataSource Expression
?
我想象是这样的:
new JRBeanCollectionDataSource(${jobs}.get($index).getResponsabilities())
但是我不能让它正常工作
but I can't get it work this
推荐答案
我找到了解决方案:
在列表中,我创建了一个名为 jobInstance
Into the list, I created a variable called jobInstance
<field name="jobInstance" class="com.mypackage.example.Job">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
然后,当我为职责列表设置数据源时,会执行以下操作:
Then when I set the datasource for responsibilities list did this:
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{jobInstance}.getResponsabilities())
参考文献: https://community.jaspersoft.com/questions/508346 /getting-current-object
这篇关于列表到其他列表中的碧玉报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!