Jump to content
We've recently updated our Privacy Statement, available here ×

SubReport and Beans


xavixxxx

Recommended Posts

Hello,

I have problem with subReport and beans.

I have the following java code to create the Main report. ( The object used are described in the source code )

        JasperDesign jasperDesign = JRXmlLoader.load( filepath );
        JasperReport jasperReport = JasperCompileManager.compileReport( jasperDesign );

        List<ObjectVO> objectVOList = new ArrayList<ObjectVO>();
        objectVOList .add( ObjectVO );

        JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport ,   new JRBeanCollectionDataSource( objectVOList ) );
        JasperExportManager.exportReportToPdfFile( jasperPrint , filepath );


I have added in the classpath a jar containing the two objects ObjectVo and AnotherObjectVO.

In my mainReport, i have the code below to include  the subReport in the detail band :

        <subreport>
                <reportElement x="27" y="11" width="502" height="54"/>
                <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{anotherObjectVOList})]]></dataSourceExpression>
                <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "subReport.jasper"]]>  </subreportExpression>
            </subreport>

And in my subReport i have the following code in the detail band  :

            <textField>
                <reportElement x="348" y="5" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{description}]]></textFieldExpression>
            </textField>

I doesn't work and i don't understand why ? I have the following error :

1. JRBeanCollectionDataSource cannot be resolved to a type
                value = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_anotherObjectVOList.getValue())));
                                                                       <------------------------>
2. JRBeanCollectionDataSource cannot be resolved to a type
                value = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_anotherObjectVOList.getOldValue()))
                                                                       <------------------------>
3. JRBeanCollectionDataSource cannot be resolved to a type
                value = (net.sf.jasperreports.engine.JRDataSource)(new JRBeanCollectionDataSource(((java.util.List)field_anotherObjectVOList.getValue())));
                                                                       <------------------------>

I have already see this error in another post but i there was'nt the solution.
Could you help me ?It's a little bit urgent.

Thanks in advance

Xavixxxx

Code:


Post Edited by at 11/09/2009 16:07
Link to comment
Share on other sites

  • 4 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Thanks for your answer Lucian. It works fine.

But i have still a problem. The subReport with the data coming from anotherObjectVOList doesn't appear on the PDF and i don't know why.

Does anyone see a problem in my jrxml (part of the file) or in my code ?

 

If i compile the report in the code, must i compile the subreport in the method too ? or it could work if the report is compiled in the code and the subreport is inserting directly in the report (as what i have tried above )

I have tried to find good examples or documentation on this point but i haven' t found. If you have that, I am interested.

Thanks in advance.

Xavixxxx

Link to comment
Share on other sites

Subreports are not automatically compiled, so you will have to make sure yourself that the subreport is compiled and present at the location where the master is looking for it.

If you want to see JR samples read the "READ THIS FIRST! - Documentation and Samples Here!" post at the top of the JR forum list.

Regards,

Lucian

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...