Home
Analytics
Passing Map Collection to scripted dataset
Sphatan
Hi I am new to Brrt Reports.<br />
<br />
I am using Birt 2.6 in eclipse Helios.<br />
I am trying to pass a Hasp Map to a scripted data set.<br />
<br />
<strong class='bbc'><span class='bbc_underline'>MapDAo.java:</span></strong><br />
<br />
package Test;<br />
<br />
public class MapDao {<br />
<br />
public MapReport getReportVO(String string) {<br />
MapReport map = new MapReport();<br />
map.addMapReport("identity.FirstName", "Julie");<br />
map.addMapReport("identity.LastName", "Chan");<br />
<br />
return map;<br />
}<br />
}<br />
<br />
<strong class='bbc'><span class='bbc_underline'>My Bean Class-MapReport .java</span></strong><br />
<br />
package Test;<br />
<br />
import java.util.HashMap;<br />
import java.util.Map;<br />
<br />
public class MapReport {<br />
<br />
<br />
<br />
private Map<String, Object> mapReport = new HashMap<String, Object>();<br />
<br />
public Map<String, Object> getMapReport() {<br />
return mapReport;<br />
}<br />
<br />
public void setMapReport(Map<String, Object> mapReport) {<br />
this.mapReport = mapReport;<br />
}<br />
<br />
public void addMapReport(String mapKey, Object value) {<br />
mapReport.put(mapKey, value);<br />
}<br />
<br />
public Object getMapReport(String mapKey) {<br />
System.out.println("mapReport.get(mapKey)"+mapReport.get(mapKey));<br />
return mapReport.get(mapKey);<br />
}<br />
<br />
<br />
}<br />
<br />
<span class='bbc_underline'><strong class='bbc'>in data Source Open function:</strong></span><br />
<br />
util = new Packages.Test.MapDao();<br />
<br />
reportVO=util.getReportVO("Julie");<br />
currentrow = 0;<br />
totalrows=1;<br />
<br />
<br />
if(currentrow){<br />
datasetRow["FirstName"] = reportVO.getMapReport("FirstName");<br />
datasetRow["LastName"] = reportVO.getMapReport("LastName");<br />
<br />
<br />
currentrow++;<br />
return true;<br />
}<br />
<br />
return false;<br />
<br />
<br />
With the above coding I am not able to get anything in my Preview Results.<br />
<br />
Thanks,
Find more posts tagged with
Comments
JasonW
What does your fetch method look like?
It should look something like:
if(currentrow < totalrows){
datasetRow["FirstName"] = reportVO.getMapReport("identity.FirstName");
datasetRow["LastName"] = reportVO.getMapReport("identity.LastName");
currentrow++;
return true;
}
return false;
Here are some links to some example scripted data sets:
http://www.eclipse.org/birt/phoenix/examples/scripting/scripteddatasource/
http://www.vogella.de/articles/EclipseBIRT/article.html
Jason
johnw
You need a fetch() method to go with the open() method. And it should go into the Data Set, not the Data Source.
Also, this is a strange issue, but if you do not surround the true and false with () in the fetch method, it will error out.
JasonW
John,
You should not have to surrond the true and false return statements with (). What version do you see that error happening in?
Jason
Sphatan
I placed the below code in the fetch method of the dataset,but still i am not able to see anything in the preview results!!!!!..
if(currentrow<totalrows){
datasetRow["FirstName"] = reportVO.getMapReport("identity.FirstName");
datasetRow["LastName"] = reportVO.getMapReport("identity.LastName");
currentrow++;
return true;
}
return false;
Sphatan
I placed the below code in the fetch method of the dataset,but still i am not able to see anything in the preview results!!!!!..
if(currentrow<totalrows){
datasetRow["FirstName"] = reportVO.getMapReport("identity.FirstName");
datasetRow["LastName"] = reportVO.getMapReport("identity.LastName");
currentrow++;
return true;
}
return false;
Sphatan
Please Help me out <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/public/style_emoticons/'>http://www.birt-exchange.org/org/forum/public/style_emoticons/</a><#EMO_DIR#>/confused.gif
JasonW
Can you modify the code to print some information like:
if(currentrow<totalrows){
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "c:/temp/fetchevents.txt", true ) );
out.println( "Mp Rep " + reportVO.getMapReport("identity.FirstName"));
out.close();
datasetRow["FirstName"] = reportVO.getMapReport("identity.FirstName");
datasetRow["LastName"] = reportVO.getMapReport("identity.LastName");
Jason
Kosaraju
When ever you try to use the scripted data sources, in the open() script function we import packages just as below
importPackage(Packages.com.myBirt.report);
Now ensure that the report and compiled class/jar file are in the same hierarchy. Report can pick the underlying class only if its in the same location.I have done the same thing and it fetches data appropriately.
Regards,
Naveen.