Home
Analytics
Nested lists
dee_jgd
I want to design a report using subreports and nested lists using a scripted dataset. I am new to Birt and do not know if this is the correct approach.
The data looks like the following -
Parent : parentName, List<Children>
Children : childName, List<Hobbies>
Hobbies : title
I pass List<Parent> to the report and want to use subreports to fill in the hobbies per child. I created a datasource. When creating the dataset, how do I define the columns? i.e. easy to add a column for PARENT_NAME, but how do I define CHILDREN? Is it possible to use this type of data structure in BIRT?
Thanks!
Dee
Find more posts tagged with
Comments
mwilliams
Hi Dee,
So you have parent, child, and hobby data sets? Can you explain more about your issue?
dee_jgd
Hi Michael <br />
<br />
I played around yesterday and found that using SubReports allows this. <br />
I am ignoring the hobbies for now and working on displaying parents and children. However, I am still not completely there.<br />
<br />
This is what I have coded in Master.rptdesign:<br />
<br />
<strong class='bbc'>Datasource and DataSet</strong><br />
-Datasource: parentDS (scripted DS)<br />
<br />
-DataSet 1 : parentSet with output columns : PARENT_NAME, CHILDREN_SET of type ANY.<br />
<br />
-DataSet 2: childrenSet with output column : CHILD_NAME<br />
<br />
<strong class='bbc'> DataSet 1 (parentSet) script for open and fetch</strong><br />
<strong class='bbc'>- open script:</strong><br />
gsh = new Packages.test.pojo.Parent(); <br />
parents = gsh.getReportList(); <br />
i = parents.iterator();<br />
<br />
<strong class='bbc'>- fetch script:</strong><br />
if (!i.hasNext()){<br />
return false;<br />
}<br />
var parent = i.next();<br />
row["PARENT_NAME"] = parent.getParentName();<br />
row["CHILDREN_SET"] = parent.getChildren();<br />
return true;<br />
<br />
<strong class='bbc'> DataSet 2 (childrenSet) script for open and fetch</strong><br />
<strong class='bbc'>- open script</strong><br />
j=childrenSet.iterator();<br />
<br />
In the Master design file, where I display the child name I use expression builder to define : <br />
childrenSet = row["CHILDREN_SET"]; <br />
row["CHILD_NAME"]<br />
<br />
<strong class='bbc'>- fetch</strong><br />
if ( !j.hasNext() ){<br />
return false ;<br />
}<br />
child = j.next();<br />
row["CHILD_NAME"] = child.getName() ; <br />
return true ;<br />
<br />
<br />
I followed this example : <a class='bbc_url' href='
http://dev.eclipse.org/newslists/news.eclipse.birt/msg03019.html'>[news.eclipse.birt]
Re: Pojo's and a scripted subreport</a><br />
<br />
When previewing, I get the an error. Can you advise on where I have gone wrong please?<br />
<br />
Unhandled exception when executing script <br />
Error.UnhandledScriptError ( 1 time(s) )<br />
detail : org.eclipse.birt.report.engine.api.EngineException: Unhandled exception when executing script at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:178) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:168) at org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleFetch(ScriptDataSetScriptExecutor.java:119) at org.eclipse.birt.data.engine.impl.ScriptDataSetRuntime.fetch(ScriptDataSetRuntime.java:102) at org.eclipse.birt.data.engine.impl.PreparedScriptDSQuery$ScriptDSQueryExecutor$CustomDataSet.fetch(PreparedScriptDSQuery.java:257) at org.eclipse.birt.data.engine.executor.cache.OdiAdapter.fetch(OdiAdapter.java:150) at ......<br />
(PoolTcpEndpoint.java:584) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:619)<br />
Caused by: org.eclipse.birt.data.engine.core.DataException: data.engine.BadFetchScriptReturnType at org.eclipse.birt.report.engine.script.internal.ScriptDataSetScriptExecutor.handleFetch(ScriptDataSetScriptExecutor.java:109) ... 101 more
dee_jgd
The error is because of a line in the fetch statement:
row["CHILDREN_SET"] = parent.getChildren();
In the POJO, .getChildren returns a java.util.Set. I also tried a List but get same error. If I change the fetch to
row["CHILDREN_SET"] = parent.getParentName(); it works.
.getParentName returns a String. It seems to be an error in putting the Set into the CHILDREN_SET of type ANY.
Please help.