Reputation: 309
I'm facing the following doubt related to pass info from a JEE web app to ireport in order to fill a table in jasper.
In Ireport when I'm creating a datasource from a java bean, it's asking me a static method that it will send data to jasper and use it to complete the table. However, every time I try to implement a static function in a state/statless/managed bean and call the class that has the Collection to display in jasper It says "non-static variable XX cannot be referenced from a static context".
I know it is happening because I need to create an EJB instance inside the static method and fill the collection to be returned. But I shouldn't create EJB instances, even if I could, the new instance wouldn't have the same info that the current EJB context has.
I haven't found a workaround method in order to solve this. Do you have any recomendations?
I'm using JSF 2, java EJB , JPA and glassfish 3.1
Thank you,
Upvotes: 1
Views: 914
Reputation: 309
Jasper documentation is not so simple to understand and It may confuse you most of the time. What I did was create an additional JRBeanCollectionDataSource attribute in the class that i sent to the report through bean injection. This new attribute let me send an Collection (a list) and in jasper reports, I declared inside the table a datasource which value is the bean's attribute I mentioned before.
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="DosCoulmnas" uuid="1364a3ee-d385-49a0-9d12-e5bdd95832ac">
<datasetParameter name="encabezados">
<datasetParameterExpression><![CDATA[$F{dtoPDFAreaYGrado1.dtoEstablecimiento}.getEncabezados()]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[$F{dtoPDFAreaYGrado1.dtoEstablecimiento}.getDatos()]]></dataSourceExpression>
</datasetRun>
Upvotes: 2
Reputation: 2258
Instead of static methods, try using bean injection, so you can have a reference to the current state of the bean, and use it's method from it.
Upvotes: 1