I have a report backed by a collection of MyJavaBean.
In this report I (of course) can get the properties of MyJavaBean declaring them in the Fields and using it on the details band, so far so good.
Now I want to be able to pass this MyJavaBean as a parameter of a subreport. Look that I want to be able to pass the javabean itself, not one of its propertys.
How can I make reference to one element of my collection in the detais band?
Referencing a bean
To declare a field that references the bean itself instead of one of its properties, set the field description to the keyword _THIS.
<field name="myJavaBean" class="com.your.package.MyJavaBean">
<fieldDescription>_THIS</fieldDescription>
</field>
You can then pass this as a subreport parameter like any other field.
<subreportParameter name="myJavaBean">
<subreportParameterExpression>
<![CDATA[$F{myJavaBean}]]>
</subreportParameterExpression>
</subreportParameter>
Methods in the bean can be called in the normal way, i.e: $F{myJavaBean}.someMethod()
Referencing a single element of the collection
Depending on what you are doing here it could be more difficult. If you want to only see the detail for the single element, set the printWhenExpression on the band to the key of the element you want. However, if you want to have some report elements reference one object in the collection while the rest of the band references another, it would probably be better for you to nest another subreport within the detail band.
Related
I have a parent report with a dynamic where clause, which is passed as $P!{WHERE_CLAUSE}, and the where clause in turn contains $P{} parameters
Eg: $P!{WHERE_CLAUSE}=> where docno between $P{P_FROMDOCNO} and $P{P_TODOCNO}
Values for $P{P_FROMDOCNO} and $P{P_TODOCNO} are also passed in the same execution
The parent report has a subreport, that summarizes based on certain category, whose query is based on the parent's where clause.
select vat,sum(amt) from tablename $P!{WHERECLAUSE} order by vat
So the where clause is passed to the sub-report using parameter mapping. But the subreport fails to read $P{P_FROMDOCNO} and $P{P_TODOCNO} values from the parent, resulting in empty document. All the above parameters have been mapped to the subreport parameters. The main goal is to fire the query in the database with bind parameters, even for the sub reports.
Kindly let me know if any solution for the above.
Edit: My question is not a duplicate of the mentioned question in the comments section. Because my subreport receives all the mapped parameter values, but the dynamic where clause($P!{WHERECLAUSE_SUB} which has the $P{P_FROMDOCNO} and $P{P_TODOCNO} fails to evaluate.
Thanks in advance,
Geetha
So I've been able to make a second data source, pass down parameters, im all but ready, but I cant figure out how to send a collection of the field values in a column to the sub report. Ive tried setting a variable to the field value and sending that, I've tried sending the field directly.
I sort of assumed these wouldn't work because the data type is wrong, but i just don't know how to tell jasper that i want the fields as a collection.
I use this in JasperSoft Studio 5.6.0 and it work fine :
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{subReportDataField})]]></dataSourceExpression>
Where "subReportDataBean" is a field like this :
<field name="subReportDataBean" class="java.util.List">
<fieldDescription><![CDATA[subReportDataBean]]></fieldDescription>
</field>
I have report that uses a subreport, but since the subreport is stored in a database table as BLOB, I cannot give its path (url) in the *.jrxml file. Is there a way to add a *.jasper file loaded from the database (BLOB or InputStream) as a subreport.
I figured it out.
Add a list component
In the list's dataset fetch the field you keep your subreport as a BLOB, lets call it
REPORT_DATA.
Set REPORT_DATA field's type to InputStream.
Add the subreport inside the list.
Set "Subreport Expression" to $F{REPORT_DATA} and its "Expression
Class" to InputStream.
Set Connection type, expression, and parameters accordingly.
Don't forget to resize the list component at least to the subreport's size, otherwise you get an error like :
net.sf.jasperreports.engine.design.JRValidationException: Band height validation for subreport ...
I have a problem with a report, I pass a array of values to report (from Java code) and that information is loaded inside the report (that works fine). But, I need to pass that field values to a table component, I saw and I can pass parameters to table, but I need use the main field values inside of table component and print that data there (in table component).
I suppose you pass the data from java as datasource. You have to pass the datasource for the table in a parameter and run the report with a different datasource (may be empty if you don't need any data). Then set the table datasource to be that parameter and declare the fields in the subdataset of the table.
See
How to show JRBeanCollectionDataSource data with help of Table component?
or
Two DataSource in report
for examples.
I've got a datasource object that contains a Collection of other objects.
For example I'm returning a Manager object that contains a List of Employees.
I'm returning back JRDataSource object of type Manager to the actual jasper report. I'm unclear on how I can loop through the employees in the jasper report itself using the $F field tags.
I use a subreport to show the objects of the Collection
use new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{the collectin}) as the subreport's data sourse expression