How to access the root element of a data source in jasperreports

I have a report contained in the MyJavaBean collection.

In this report, I (of course) can get the properties of MyJavaBean, declaring them in the Fields and using it in the detail bar, how good it is.

Now I want to pass this MyJavaBean as a subtitle parameter. Listen to what I want so that I can convey the jawab itself, and not one of its properties.

How can I reference one element of my collection in the detais group?

+6
source share
1 answer

Link to bean

To declare a field that refers to the bean itself, and not one of its properties, specify a field description for the _THIS .

 <field name="myJavaBean" class="com.your.package.MyJavaBean"> <fieldDescription>_THIS</fieldDescription> </field> 

You can pass this as a subtitle parameter, like any other field.

 <subreportParameter name="myJavaBean"> <subreportParameterExpression> <![CDATA[$F{myJavaBean}]]> </subreportParameterExpression> </subreportParameter> 

Methods in a bean can be called in the usual way, that is: $F{myJavaBean}.someMethod()

Link to one item in the collection

Depending on what you are doing here, this can be tricky. If you want to see only the details for an individual element, set printWhenExpression on the strip the key of the desired element. However, if you want some report elements to refer to one object in the collection, and the rest of the group refer to another, you would probably be better off if you nested another subreport in a range of details.

+11
source

Source: https://habr.com/ru/post/893873/


All Articles