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

subReport woes (passing data)


johan.andersson

Recommended Posts

Hi,

I am using a very old jasperreports library (2.0.4) which is installed at a customer site, I am not allowed to upgrade it at this time.

They have the data that needs to be reported in a non SQL based old system, and I do calls to the reports and use jasper templates

I finally got the main report to show it's colors a day or so back, but now I am trying to add a subreport to it where the datasource is NOT an SQL Query.

basically I got the data in as an array of objects which in turn has the "fields" I need the report to print.
I could of course, loop through this list and build something out of it before I call the report, and I will do that if nessesary

But at this moment, I am getting nothing through, not even the static texts in the subreport.

I would be extremely grateful for some very simple working example of a master.jrxml which calls a subreport.jrxml with parametrized data like the one I got
or at least one that send it through the call to the masters fillReport via the map in such a way that the subReport can pick it up as a multicolumn datafeed.
What I have basically is the master report with no info on the subreport, in fact the whole detail band is empty in the exported xml
 

This is my parametermap that I send in to fillReport {
  RoleCode=1X6B1XX,
  FlagReportTemplate=null,
  FlagObjList=[GenericObject:PIMS, GenericObject:FTSO, GenericObject:PTSO],
  RuleObjList=[GenericObject:CCRL010?, GenericObject:CCRL020?, GenericObject:CRBO010?, GenericObject:CRBO020?, GenericObject:CRBO030?,
                       GenericObject:CRBO040?, GenericObject:CRBO050?, GenericObject:CRBO060?, GenericObject:LBDE1, GenericObject:LSTD1BEH, GenericObject:LZFU,
                       GenericObject:LZOT, GenericObject:PARGU200, GenericObject:SPR],
  RoleOwners=S22X68,SY6025,
  RoleDescription=NNN IT - Development - Developer SAS,
  RuleReportTemplate=net.sf.jasperreports.engine.JasperReport@1032529
}

This is the subReport.jrxml

<?xml version="1.0" encoding="UTF-8"  ?><!-- Created with iReport - A designer for JasperReports --><!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport   name="NNN-ruleSubReport"   columnCount="3"   printOrder="Vertical"   orientation="Portrait"   pageWidth="595"   pageHeight="842"   columnWidth="178"   columnSpacing="0"   leftMargin="0"   rightMargin="0"   topMargin="0"   bottomMargin="0"   whenNoDataType="NoPages"   isTitleNewPage="false"   isSummaryNewPage="false"><property name="ireport.scriptlethandling" value="0" /><property name="ireport.encoding" value="UTF-8" /><import value="java.util.*" /><import value="net.sf.jasperreports.engine.*" /><import value="net.sf.jasperreports.engine.data.*" /> <parameter name="RoleCode" isForPrompting="false" class="java.lang.String"/><parameter name="RoleSubReport" isForPrompting="false" class="java.lang.Object"/><parameter name="RuleObjList" isForPrompting="false" class="java.lang.Object"/> <field name="rule" class="java.lang.String"/><field name="description" class="java.lang.String"/><field name="system" class="java.lang.String"/>  <background>   <band height="0"  isSplitAllowed="true" >   </band>  </background>  <title>   <band height="0"  isSplitAllowed="true" >   </band>  </title>  <pageHeader>   <band height="0"  isSplitAllowed="true" >   </band>  </pageHeader>  <columnHeader>   <band height="20"  isSplitAllowed="true" >    <rectangle>     <reportElement      mode="Transparent"      x="0"      y="0"      width="80"      height="20"      forecolor="#999999"      key="rectangle-1"/>     <graphicElement stretchType="NoStretch" pen="Thin"/>    </rectangle>    <rectangle>     <reportElement      mode="Transparent"      x="80"      y="0"      width="430"      height="20"      forecolor="#999999"      key="rectangle-2"/>     <graphicElement stretchType="NoStretch" pen="Thin"/>    </rectangle>    <rectangle>     <reportElement      mode="Transparent"      x="510"      y="0"      width="85"      height="20"      forecolor="#999999"      key="rectangle-3"/>     <graphicElement stretchType="NoStretch" pen="Thin"/>    </rectangle>    <staticText>     <reportElement      mode="Opaque"      x="0"      y="0"      width="80"      height="20"      forecolor="#000000"      backcolor="#CCCCCC"      key="staticText-1"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement verticalAlignment="Middle">      <font fontName="NNN Basic" size="12" isBold="true"/>     </textElement>    <text><![CDATA[Rule]]></text>    </staticText>    <staticText>     <reportElement      mode="Opaque"      x="80"      y="0"      width="430"      height="20"      forecolor="#000000"      backcolor="#CCCCCC"      key="staticText-2"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement verticalAlignment="Middle">      <font fontName="NNN Basic" size="12" isBold="true"/>     </textElement>    <text><![CDATA[Description]]></text>    </staticText>    <staticText>     <reportElement      mode="Opaque"      x="510"      y="0"      width="85"      height="20"      forecolor="#000000"      backcolor="#CCCCCC"      key="staticText-3"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement verticalAlignment="Middle">      <font fontName="SEB Basic" size="12" isBold="true"/>     </textElement>    <text><![CDATA[system]]></text>    </staticText>   </band>  </columnHeader>  <detail>   <band height="81"  isSplitAllowed="true" >    <rectangle>     <reportElement      x="0"      y="0"      width="80"      height="18"      forecolor="#999999"      key="rectangle-5"/>     <graphicElement stretchType="NoStretch" pen="Thin"/>    </rectangle>    <rectangle>     <reportElement      x="80"      y="0"      width="430"      height="18"      forecolor="#999999"      key="rectangle-4"/>     <graphicElement stretchType="NoStretch" pen="Thin"/>    </rectangle>    <rectangle>     <reportElement      x="510"      y="0"      width="85"      height="18"      forecolor="#999999"      key="rectangle-6"/>     <graphicElement stretchType="NoStretch" pen="Thin"/>    </rectangle>    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >     <reportElement      x="0"      y="0"      width="80"      height="18"      key="textField"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement verticalAlignment="Middle">      <font fontName="NNN Basic" size="12"/>     </textElement>    <textFieldExpression   class="java.lang.String"><![CDATA[$F{rule}]]></textFieldExpression>    </textField>    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >     <reportElement      x="80"      y="0"      width="430"      height="18"      key="textField"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement verticalAlignment="Middle">      <font fontName="NNN Basic" size="12"/>     </textElement>    <textFieldExpression   class="java.lang.String"><![CDATA[$F{description}]]></textFieldExpression>    </textField>    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >     <reportElement      x="510"      y="0"      width="85"      height="18"      forecolor="#000000"      key="textField"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement verticalAlignment="Middle">      <font fontName="NNN Basic" size="12"/>     </textElement>    <textFieldExpression   class="java.lang.String"><![CDATA[$F{system}]]></textFieldExpression>    </textField>    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >     <reportElement      x="9"      y="60"      width="84"      height="19"      key="textField-1"/>     <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>     <textElement>      <font/>     </textElement>    <textFieldExpression   class="java.lang.String"><![CDATA[$P{RoleCode}]]></textFieldExpression>    </textField>   </band>  </detail>  <columnFooter>   <band height="0"  isSplitAllowed="true" >   </band>  </columnFooter>  <pageFooter>   <band height="0"  isSplitAllowed="true" >   </band>  </pageFooter>  <summary>   <band height="0"  isSplitAllowed="true" >   </band>  </summary></jasperReport>[/code]
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Well,

As I suspected I could not get it to work with the data stacked as it is.
To get the subreport actually filling out I hade to rearrange the list of objects that I had to a List of Maps... i.e.
the ruleObjList will be converted into a ruleMapList 
 

List dataList;dataList = new java.util.ArrayList();Looping through the list of earlier objects...{  Map dataMap = new java.util.HashMap();  dataMap.put("rule", "ruledata");  dataMap.put("whatever","whatever you think data");  dataList.add(dataMap);}then add that list to the Map you send as parameters to the main report which and copy that down to the subreport in the templates....Map pm;pm = new java.util.HashMap();pm.put("ruleList", dataList);...[/code]


I had to change the receiving class in the report too...
 

<dataSourceExpression>  <![CDATA[new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($P{RuleObjList})]]></dataSourceExpression><subreportExpression  class="net.sf.jasperreports.engine.JasperReport">  <![CDATA[$P{RuleSubReport}]]></subreportExpression>[/code]

But it looks like it works this way at least...

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...