teodanciu Posted December 29, 2010 Share Posted December 29, 2010 Hello, I'm trying to generate a report with a table which contains data from the main data source.However, I'm pretty stuck, because the table simply isn't displayed in the report (although no error is reported).This is what I want to obtain: Territory east west However, the report contains a simple horizontal line instead of the table. I'm trying to use the jr:table as follows: 1) First, I'm using a JRBeanArrayDataSource constructed with the following array of objects: public static Object[] createBeanCollection() { Object[] reportRows= new Object[2]; reportRows[0] = new FilterData("east"); //public FilterData(String territory) reportRows[1] = new FilterData("wast"); return reportRows; } where FilterData is a simple javabean, having a "territory" property. 1) In my jrxml, I declared a subdataset containing the territory field. <subDataset name="Table Dataset 1"> <field name="territory" class="java.lang.String"/></subDataset> ( I am not sure if this approach is ok. Does declaring the field "territory" in the subDataset enable me to use $F{territory} in jr:detailCell? Because this is what I'm doing...and it doesn't work).2) I'm trying to use this subDataset in a jr:table, as follows: (in the <detail> <band> section) <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="Table Dataset 1"> <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression> </datasetRun> <jr:column width="90"> <jr:columnHeader style="table_CH" height="30"> <staticText> <reportElement x="0" y="0" width="90" height="30"/> <text><![CDATA[Territory]]></text> </staticText> </jr:columnHeader> <jr:detailCell style="table_TD" height="20"> <textField> <reportElement x="0" y="0" width="90" height="20"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{territory}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> </jr:table> Do you have any idea on what I' m doing wrong here? Thanks a lot! Teo Code: public static Object[] createBeanCollection() { Object[] reportRows= new Object[2]; reportRows[0] = new FilterData("east"); //public FilterData(String territory) reportRows[1] = new FilterData("wast"); return reportRows; }<subDataset name="Table Dataset 1"> <field name="territory" class="java.lang.String"/></subDataset><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="Table Dataset 1"> <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression> </datasetRun> <jr:column width="90"> <jr:columnHeader style="table_CH" height="30"> <staticText> <reportElement x="0" y="0" width="90" height="30"/> <text><![CDATA[Territory]]></text> </staticText> </jr:columnHeader> <jr:detailCell style="table_TD" height="20"> <textField> <reportElement x="0" y="0" width="90" height="20"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{territory}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column></jr:table> Link to comment Share on other sites More sharing options...
sebajb Posted July 10, 2012 Share Posted July 10, 2012 Did you ever get an answer to this question? I am having the exact same problem. Mind sharing? Link to comment Share on other sites More sharing options...
teodanciu Posted July 10, 2012 Author Share Posted July 10, 2012 Hi ,It's been a while since then, but I recall:1) wrapping the JRBeanArrayDataSource into a JRMapArrayDataSource, like this : Map[] masterData = new Map[1]; masterData[0] = new HashMap(); masterData[0].put("filterDataSource", filterDataSource); //I had other similar dataSources and then created and passed the data source like this: new JRMapArrayDataSource(masterData)2) The, in the jrxml file, I replaced the $P{REPORT_DATA_SOURCE} with $F{filterDataSource}. Something like this: <subDataset name="filterDataSet"> <field name="territory" class="java.lang.String"/></subDataset><field name="filterDataSource" class="net.sf.jasperreports.engine.data.JRBeanArrayDataSource"/>and in the table: <jr:table> <datasetRun subDataset="filterDataSet"> <dataSourceExpression><![CDATA[$F{filterDataSource}]]></dataSourceExpression> </datasetRun> <jr:column width="90"> <jr:columnHeader style="table_CH" height="30"> <staticText> <reportElement x="0" y="0" width="90" height="30"/> <text><![CDATA[Territory]]></text> </staticText> </jr:columnHeader> <jr:detailCell style="table_TD" height="20"> <textField> <reportElement x="0" y="0" width="90" height="20"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{territory}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> </jr:table> I don't know whether this is the "orthodox" solution for this, but it worked for me. Also, i posted this question on stackoverflow as well (http://stackoverflow.com/questions/4563176/jasper-table-component),and someone seems to have found the answer: <datasetRun subDataset="TableDataset"> <datasetParameter name="REPORT_DATA_SOURCE"> <datasetParameterExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></datasetParameterExpression> </datasetParameter> </datasetRun>[/code] But I haven't tested this (since it came a bit too late), but maybe it works for you. Hope this helps! Teo Post Edited by teodanciu at 07/10/2012 19:59 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