java - Fill data of sub report with master report field value -


i'm using ireport 5.0.

my subreport not receiving list if objects needs show. how give list main report subreport, without using db connection.

to explain situation:
-i have list of questions, each question have list of answers , percentage of correct ones.

so on java:

jrbeancollectiondatasource beancollection2 = new jrbeancollectiondatasource(listofquestions); jasperprint jasperprint2 = jasperfillmanager.fillreport(facescontext.getcurrentinstance().getexternalcontext().getresourceasstream("/resources/report/surveygeneralreport.jasper"),                 new hashmap<string,object>(), beancollection2) ; 

on surveygeneralreport.jrxml have:

<parameter name="root_dir" class="java.lang.string" isforprompting="false">     <defaultvalueexpression><![cdata["example\\resources\\report\\"]]></defaultvalueexpression> </parameter> <parameter name="subreport_dir" class="java.lang.string" isforprompting="false">     <defaultvalueexpression><![cdata[$p{root_dir} + "subreport\\"]]></defaultvalueexpression> </parameter> . . . . <detail>         <band height="68" splittype="stretch">             <textfield>                 <reportelement uuid="bdd12e8b-f8f6-4aea-b2ff-d17255fb6559" x="0" y="0" width="100" height="20"/>                 <textelement/>                 <textfieldexpression><![cdata[$f{question}]]></textfieldexpression>             </textfield>             <subreport>                 <reportelement uuid="01c7d5a6-c89d-4c56-a14e-18ac5eeb1a71" x="100" y="20" width="415" height="48"/>                 <subreportparameter name="answers">                     <subreportparameterexpression><![cdata[$f{answers}]]></subreportparameterexpression>                 </subreportparameter>                 <subreportexpression><![cdata[$p{subreport_dir} + "answersubreport.jasper"]]></subreportexpression>             </subreport>         </band>     </detail> 

on answersubreport.jrxml:

<parameter name="answers" class="java.util.collection"/> <field name="answervalue" class="java.lang.string"/> <field name="answerpercentage" class="java.lang.string"/> 

so how tell subreport iterate on answers parameter?

my exception is:

15:12:21,821 error [org.apache.catalina.core.containerbase.[jboss.web].[localhost].[/admin/round].[faces servlet]] servlet.service() para servlet faces servlet lanzó excepción: java.lang.nullpointerexception @ net.sf.jasperreports.engine.fill.jrprintband.addoffsetelements(jrprintband.java:101) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrfillelementcontainer.addsubelements(jrfillelementcontainer.java:623) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrfillelementcontainer.fillelements(jrfillelementcontainer.java:600) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrfillband.fill(jrfillband.java:406) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrfillband.fill(jrfillband.java:352) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrverticalfiller.fillcolumnband(jrverticalfiller.java:2023) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrverticalfiller.filldetail(jrverticalfiller.java:755) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrverticalfiller.fillreportstart(jrverticalfiller.java:265) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrverticalfiller.fillreport(jrverticalfiller.java:128) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrbasefiller.fill(jrbasefiller.java:836) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrbasefiller.fill(jrbasefiller.java:765) [:4.1.3] @ net.sf.jasperreports.engine.fill.jrfiller.fillreport(jrfiller.java:84) [:4.1.3] @ net.sf.jasperreports.engine.jasperfillmanager.fillreport(jasperfillmanager.java:624) [:4.1.3] @ net.sf.jasperreports.engine.jasperfillmanager.fillreport(jasperfillmanager.java:605) [:4.1.3] 

if can more clear please ask me more detail.

i found solution here

what did data source expression,

new net.sf.jasperreports.engine.data.jrbeancollectiondatasource($f{answers}) 

Comments