JasperReports字段的自定义类 [英] Custom Class for JasperReports field

查看:129
本文介绍了JasperReports字段的自定义类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个包含自定义类的报告,如下所示:

I would like to create a report with a custom class as follows:

public class Class1 {
  String cl1_f1;
  String cl1_f2;
}

public class Class2 {
   String cl2_f1;
   String cl2_f2;
   Class1 cl1_ob1;
}

现在我通过字段在报告中传递 Class2 和JRBeanCollectionDataSource。

Now I pass Class2 in the report through fields and JRBeanCollectionDataSource.

<subDataset name="myitems">
    <field name="cl2_f1" class="java.lang.String"/>
    <field name="cl2_f2" class="java.lang.String"/>
    **<field name="cl1_ob1" class="Class2"/>**  
</subDataset>

对于第三个参数,我想提一下它的一个字段。例如: cl1_ob1.cl1_f1

For the third parameter, I would like to mention one of its fields. For example: cl1_ob1.cl1_f1.

我该如何做到这一点?

推荐答案

在Jasper报告设计中,该字段定义如下:

In the Jasper report design, the field will be defined as below:

<field name="cl1_ob1" class="Class1">
   <fieldDescription><![CDATA[cl1_ob1]]></fieldDescription>
</field>

可以通过调用getter方法(如果有的话)访问Class1的2个变量或者你可以直接使用变量,具体取决于它的访问权限。例如, $ F {cl1_ob1} .getCl1_f1()可用作文本字段表达式,如下所示:

And the 2 variables of Class1 can be accessed by calling the getter method (if there is one) or you can use the variable directly, depending on it's access privileges. For Example, $F{cl1_ob1}.getCl1_f1() can be used as a text-field expression, as shown below:

<textField>
   <reportElement x="36" y="26" width="235" height="20"/>
   <textElement textAlignment="Center" verticalAlignment="Middle"/>
   <textFieldExpression><![CDATA[$F{cl1_ob1}.getCl1_f1()]]></textFieldExpression>
</textField>

这篇关于JasperReports字段的自定义类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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