2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Ulf Heyder - olpp Subreport question 2003-01-13 08:34 I have a problem with my subreport. The datasource for the mainreport has the fields KEY and NAME. The datasource for the subreport has the fields KEY and INFO and is passed to it by the main report through a parameter tag: <parameter name="subDataSource" class="dori.jasper.engine.JRDataSource"/> ... <dataSourceExpression> $P{subDataSource} </dataSourceExpression> My problem now is, that the result looks like ------------------------ key1 name1 info11 info12 info21 info22 info31 key2 name2 key3 name3 ------------------------ instead of ------------------------ key1 name1 info11 info12 key2 name2 info21 info22 key3 name3 info31 ------------------------ I don't know, how I can tell the subreport to print only the infos wich belong to the corresponding key. The examples only show how to make it with where-clauses in queries. Can I pass a fieldname to the subreport to filter the sub-datasource? Any help? Please see the excerpts of the report files below. I can also send the files per email. Thanks, Ulf ----------------- begin excerpt mainreport.xml --------------------------------- <parameter name="subDataSource" class="dori.jasper.engine.JRDataSource"/> <field name="NAME" class="java.lang.String"/> <field name="KEY" class="java.lang.String"/> <detail> <band height="32"> <textField isStretchWithOverflow="true"> <reportElement x="0" y="0" width="55" height="13"/> <textFieldExpression class="java.lang.String"> $F{KEY} </textFieldExpression> </textField> <textField isBlankWhenNull="true"> <reportElement x="55" y="0" width="500" height="13"/> <textFieldExpression class="java.lang.String"> $F{NAME} </textFieldExpression> </textField> <subreport isUsingCache="true"> <reportElement x="5" y="15" width="325" height="15" isPrintRepeatedValues="false" isPrintWhenDetailOverflows="false" isRemoveLineWhenBlank="true"/> <subreportParameter name="KEY"> <subreportParameterExpression> $F{KEY} </subreportParameterExpression> </subreportParameter> <dataSourceExpression> $P{subDataSource} </dataSourceExpression> <subreportExpression class="java.lang.String"> "X:/Privat/UHeyder/Java/Jasper/ListeGemarkungenSub.jasper" </subreportExpression> </subreport> </band> </detail> ----------------- end excerpt mainreport.xml ----------------------------------- ----------------- begin excerpt subreport.xml ---------------------------------- <parameter name="KEY" class="java.lang.String"/> <field name="INFO" class="java.lang.String"/> <detail> <band height="11"> <textField isStretchWithOverflow="true"> <reportElement x="10" y="0" width="535" height="11"/> <textFieldExpression class="java.lang.String"> "Sub: "+$F{INFO} </textFieldExpression> </textField> </band> </detail> ----------------- end excerpt subreport.xml ------------------------------------ By: Glenn Owen - grubincan RE: Subreport question 2003-01-22 06:10 You need to filter the data in your sub report's datasource based on the data in the master row. So your subreport dataSourceExpression needs to look something like... <dataSourceExpression> ((YourDataSourceClass)$P{subDataSource}).filter($F{KEY}) </dataSourceExpression> the filter() method in your subdatasource class needs to: -filter the data in the datasource (using the passed key value) - reset the internal row pointer to row 0, so subsequent calls to next() and getFieldValue() return the filtered data. - return a reference to itself (since that's what the dataSourceExpression is expecting). You can then also remove the KEY parameter for the subreport since the master is managing the filtering. Note: I haven't tried this in XML form, I use the API interface, but it should work correctly. By: Teodor Danciu - teodord RE: Subreport question 2003-01-22 08:54 Hi, I think you have more like an "order" problem then a "filter" problem. The data source has to deal with records order because the reporting engine does not do it. There are proposed sortable data source implementations, but they are not yet part of the main distribution. Since you have already implemented a custom data source, it is there that you have to deal with the order. I hope this helps. Teodor By: Stephen Ho - sfgear RE: Subreport question 2003-06-10 10:01 Hi: I wonder if you can help me out regarding using DataSource in subreport. I wonder how to create a DataSource for the subreport, for the main report I had used the JRResultSetDataSource. Thanks Stephen Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now