Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Layout Problem with Scripted data set with hashmap (Hashmap contains key and arraylist )
Layout Problem with Scripted data set with hashmap [message #675865] Wed, 01 June 2011 14:41 Go to next message
Ram  is currently offline Ram
Messages: 3
Registered: May 2011
Junior Member
Hi,

I am trying to get the following layout for a report :

label1 label2 label3 label4
--------------------------------
Key1

value1 , value 2, value 3

key2

value1, value 2, value3

and i am passing a hashmap with key and arraylist of my "ReportBean" i am trying to do the following in the open and fetch operations:

------------------------------------------------------------
<property name="dataSource">MyDataSource</property>
<method name="open"><![CDATA[favoritesClass = new Packages.NewSimpleClass();
favorites = favoritesClass.readData();
iter = favorites.keySet().iterator();
//c = favorites.values();
//iter = c.iterator();
cnt = 0;]]></method>
<method name="fetch"><![CDATA[if( iter.hasNext() ){
myObject = iter.next();

row["KEY"] = myObject;

newObject = favorites.get(myObject);

iter2 = newObject.iterator();

icnt=0;
while( iter2.hasNext()){
someObject = iter2.next();

row["VALUE1"] = someObject.getvalue1();
row["VALUE2"] = someObject.getValue2();
row["VALUE3"] = someObject.getValue3();
row["VALUE4"] = someObject.getValue4();

}

return true;

}else{

return false;

}]]></method>
---------------------------------------------------------------

but i am unable to get the complete itration of the "ReportBean" I only get the data from the last "ReportBean" . How do i iterate over so that i get all the "ReportBean" value populated in the report. Any Help is greatly appreciated.

Thanks.

Re: Layout Problem with Scripted data set with hashmap [message #675870 is a reply to message #675865] Wed, 01 June 2011 14:54 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Ram,

How many rows does this return. Does this like always return the same
object?
row["KEY"] = myObject;

Jason

On 6/1/2011 2:42 PM, Ram wrote:
> Hi,
>
> I am trying to get the following layout for a report :
> label1 label2 label3 label4
> --------------------------------
> Key1
>
> value1 , value 2, value 3
>
> key2
>
> value1, value 2, value3
> and i am passing a hashmap with key and arraylist of my "ReportBean" i
> am trying to do the following in the open and fetch operations:
>
> ------------------------------------------------------------ <property
> name="dataSource">MyDataSource</property>
> <method name="open"><![CDATA[favoritesClass = new
> Packages.NewSimpleClass();
> favorites = favoritesClass.readData();
> iter = favorites.keySet().iterator();
> //c = favorites.values();
> //iter = c.iterator();
> cnt = 0;]]></method>
> <method name="fetch"><![CDATA[if( iter.hasNext() ){
> myObject = iter.next();
>
> row["KEY"] = myObject;
>
> newObject = favorites.get(myObject);
>
> iter2 = newObject.iterator();
>
> icnt=0;
> while( iter2.hasNext()){
> someObject = iter2.next();
>
> row["VALUE1"] = someObject.getvalue1();
> row["VALUE2"] = someObject.getValue2();
> row["VALUE3"] = someObject.getValue3();
> row["VALUE4"] = someObject.getValue4();
>
> }
>
> return true;
>
> }else{
>
> return false;
>
> }]]></method>
> ---------------------------------------------------------------
>
> but i am unable to get the complete itration of the "ReportBean" I only
> get the data from the last "ReportBean" . How do i iterate over so that
> i get all the "ReportBean" value populated in the report. Any Help is
> greatly appreciated.
>
> Thanks.
Re: Layout Problem with Scripted data set with hashmap [message #675876 is a reply to message #675870] Wed, 01 June 2011 15:17 Go to previous messageGo to next message
Ram  is currently offline Ram
Messages: 3
Registered: May 2011
Junior Member
Hi Jason,


I am attaching the rpt file along with the java objects i am using for the report.
In the java object i have intialized the hashmap as following:

public HashMap readData(){
HashMap rtnV = new HashMap();

Vector newA = new Vector();
ReportBean rptBean1 = new ReportBean();
rptBean1.setServiceName("Web1");
rptBean1.setBiweekly("4");
rptBean1.setYearly("1000");
rptBean1.setWeekly("10");
newA.add(rptBean1);
ReportBean rptBean2 = new ReportBean();
rptBean2.setServiceName("Web2");
rptBean2.setBiweekly("20");
rptBean2.setYearly("2000");
rptBean2.setWeekly("200");
newA.add(rptBean2);

rtnV.put("FirstWeb", newA);

Vector newB = new Vector();
ReportBean rptBean3 = new ReportBean();
rptBean3.setServiceName("Web3");
rptBean3.setBiweekly("30");
rptBean3.setYearly("3000");
rptBean3.setWeekly("300");
newB.add(rptBean3);
ReportBean rptBean4 = new ReportBean();
rptBean4.setServiceName("Web4");
rptBean4.setBiweekly("40");
rptBean4.setYearly("4000");
rptBean4.setWeekly("400");
newB.add(rptBean4);

rtnV.put("SecondWeb", newB);

Vector newC = new Vector();

ReportBean rptBean5 = new ReportBean();
rptBean5.setServiceName("Web5");
rptBean5.setBiweekly("4");
rptBean5.setYearly("1000");
rptBean5.setWeekly("10");
newC.add(rptBean5);
ReportBean rptBean6 = new ReportBean();
rptBean6.setServiceName("Web6");
rptBean6.setBiweekly("20");
rptBean6.setYearly("2000");
rptBean6.setWeekly("200");
newC.add(rptBean6);

rtnV.put("ThirdWeb", newC);

return (rtnV);
}

but i get the following output:

Report Header
Vendor Service Biweekly Yearly Weekly
FirstWeb
Web2 20 2000 200

SecondWeb
Web4 40 4000 400

ThirdWeb
Web6 20 2000 200


the items Web1 , web3 , web 5 are missing. I am not able to figure out how to get those in the report. Your comments appreciated.

Thanks.
Re: Layout Problem with Scripted data set with hashmap [message #675894 is a reply to message #675876] Wed, 01 June 2011 15:57 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Ram

The issue is that a scripted data set fetch event can only return one
row at a time. You either have to create two datasets and nest them in
the tables. See attached example of this using your class. The inner
hash dataset uses a dataset parameter which is bound to the outer table
at run time (look at inner table binding). Or you can use the BIRT java
object data type:
http://birtworld.blogspot.com/2010/10/birt-java-object-data-type.html

Nested table example attached.

Jason

<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.22"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.6.1.v20100902 Build &lt;2.6.1.v20100915-1750></property>
<property name="units">in</property>
<property name="iconFile">/templates/grouped_listing.gif</property>
<property
name="cheatSheet">org.eclipse.birt.report.designer.ui.cheatsheet.groupedlisting</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<script-data-source name="MyDataSource" id="43"/>
</data-sources>
<data-sets>
<script-data-set name="MyDataSet" id="44">
<list-property name="resultSetHints">
<structure>
<property name="position">1</property>
<property name="name">VENDOR</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">VENDOR</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">VENDOR</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">MyDataSource</property>
<method
name="open"><![CDATA[importPackage(Packages.test.birt.javaobject);
favoritesClass = new NewSimpleClass();
favorites = favoritesClass.readData();
iter = favorites.entrySet().iterator();
iter1 = favorites.keySet().iterator();]]></method>
<method name="fetch"><![CDATA[if( iter1.hasNext() ){
myObject = iter1.next();
row["VENDOR"] = myObject;
return true;
}else{
return false;
}]]></method>
<method name="close"><![CDATA[favoritesClass = null;
favorites = null;]]></method>
</script-data-set>
<script-data-set name="inner" id="85">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">SERVICE</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">1</property>
<property name="name">BIWEEKLY</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">YEARLY</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">WEEKLY</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">SERVICE</property>
</structure>
<structure>
<property name="columnName">BIWEEKLY</property>
</structure>
<structure>
<property name="columnName">YEARLY</property>
</structure>
<structure>
<property name="columnName">WEEKLY</property>
</structure>
</list-property>
<list-property name="parameters">
<structure>
<property name="name">param_1</property>
<property name="dataType">string</property>
<property name="position">1</property>
<expression name="defaultValue"
type="javascript">"MyFirstWeb"</expression>
<property name="isInput">true</property>
<property name="isOutput">false</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">SERVICE</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">BIWEEKLY</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">YEARLY</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">WEEKLY</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">MyDataSource</property>
<method
name="open"><![CDATA[importPackage(Packages.test.birt.javaobject);
favoritesClass = new NewSimpleClass();
favorites = favoritesClass.readData();
importPackage( Packages.java.io );
out = new PrintWriter( new FileWriter( "c:/test/sssdfdasfpgevents.txt",
true ) );
out.println( "beforeFactory" +inputParams["param_1"] );
out.close();
out.flush();
newObject = favorites.get(inputParams["param_1"]);
iter2 = newObject.iterator();]]></method>
<method name="fetch"><![CDATA[if( iter2.hasNext() ){
someObject = iter2.next();

row["SERVICE"] = someObject.getServiceName();
row["BIWEEKLY"] = someObject.getBiweekly();
row["YEARLY"] = someObject.getYearly();
row["WEEKLY"] = someObject.getWeekly();

return true;
}else{
return false;
}

]]></method>
</script-data-set>
</data-sets>
<styles>
<style name="report" id="38">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" id="41">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="42">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<grid id="3">
<property name="width">100%</property>
<column id="4"/>
<row id="5">
<cell id="6">
<text id="7">
<property
name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</cell>
</row>
</grid>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<grid id="8">
<property name="height">0.333in</property>
<property name="width">5.968in</property>
<column id="9"/>
<row id="10">
<property name="height">0.333in</property>
<property name="verticalAlign">text-bottom</property>
<cell id="11">
<property name="verticalAlign">top</property>
<label id="12">
<property name="fontFamily">sans-serif</property>
<property name="fontWeight">bold</property>
<property name="textUnderline">underline</property>
<property name="textAlign">center</property>
<text-property name="text">Report
Header</text-property>
</label>
</cell>
</row>
</grid>
<table id="86">
<property name="dataSet">MyDataSet</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">VENDOR</property>
<text-property
name="displayName">VENDOR</text-property>
<expression name="expression"
type="javascript">dataSetRow["VENDOR"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<column id="95"/>
<column id="99"/>
<header>
<row id="87">
<cell id="88">
<label id="89">
<text-property
name="text">VENDOR</text-property>
</label>
</cell>
<cell id="96"/>
</row>
</header>
<detail>
<row id="90">
<cell id="91">
<data id="92">
<property name="whiteSpace">nowrap</property>
<property
name="resultSetColumn">VENDOR</property>
</data>
</cell>
<cell id="97">
<table id="100">
<property name="dataSet">inner</property>
<list-property name="paramBindings">
<structure>
<property
name="paramName">param_1</property>
<simple-property-list
name="expression">
<value
type="javascript">row["VENDOR"]</value>
</simple-property-list>
</structure>
</list-property>
<list-property name="boundDataColumns">
<structure>
<property
name="name">SERVICE</property>
<text-property
name="displayName">SERVICE</text-property>
<expression name="expression"
type="javascript">dataSetRow["SERVICE"]</expression>
<property
name="dataType">string</property>
</structure>
<structure>
<property
name="name">BIWEEKLY</property>
<text-property
name="displayName">BIWEEKLY</text-property>
<expression name="expression"
type="javascript">dataSetRow["BIWEEKLY"]</expression>
<property
name="dataType">string</property>
</structure>
<structure>
<property name="name">YEARLY</property>
<text-property
name="displayName">YEARLY</text-property>
<expression name="expression"
type="javascript">dataSetRow["YEARLY"]</expression>
<property
name="dataType">string</property>
</structure>
<structure>
<property name="name">WEEKLY</property>
<text-property
name="displayName">WEEKLY</text-property>
<expression name="expression"
type="javascript">dataSetRow["WEEKLY"]</expression>
<property
name="dataType">string</property>
</structure>
</list-property>
<column id="124"/>
<column id="125"/>
<column id="126"/>
<column id="127"/>
<header>
<row id="101">
<cell id="102">
<label id="103">
<text-property
name="text">SERVICE</text-property>
</label>
</cell>
<cell id="104">
<label id="105">
<text-property
name="text">BIWEEKLY</text-property>
</label>
</cell>
<cell id="106">
<label id="107">
<text-property
name="text">YEARLY</text-property>
</label>
</cell>
<cell id="108">
<label id="109">
<text-property
name="text">WEEKLY</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="110">
<cell id="111">
<data id="112">
<property
name="whiteSpace">nowrap</property>
<property
name="resultSetColumn">SERVICE</property>
</data>
</cell>
<cell id="113">
<data id="114">
<property
name="whiteSpace">nowrap</property>
<property
name="resultSetColumn">BIWEEKLY</property>
</data>
</cell>
<cell id="115">
<data id="116">
<property
name="whiteSpace">nowrap</property>
<property
name="resultSetColumn">YEARLY</property>
</data>
</cell>
<cell id="117">
<data id="118">
<property
name="whiteSpace">nowrap</property>
<property
name="resultSetColumn">WEEKLY</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="119">
<cell id="120"/>
<cell id="121"/>
<cell id="122"/>
<cell id="123"/>
</row>
</footer>
</table>
</cell>
</row>
</detail>
<footer>
<row id="93">
<cell id="94"/>
<cell id="98"/>
</row>
</footer>
</table>
</body>
</report>


On 6/1/2011 3:17 PM, Ram wrote:
> Hi Jason,
>
>
> I am attaching the rpt file along with the java objects i am using for the report.
> In the java object i have intialized the hashmap as following:
>
> public HashMap readData(){
> HashMap rtnV = new HashMap();
>
> Vector newA = new Vector();
> ReportBean rptBean1 = new ReportBean();
> rptBean1.setServiceName("Web1");
> rptBean1.setBiweekly("4");
> rptBean1.setYearly("1000");
> rptBean1.setWeekly("10");
> newA.add(rptBean1);
> ReportBean rptBean2 = new ReportBean();
> rptBean2.setServiceName("Web2");
> rptBean2.setBiweekly("20");
> rptBean2.setYearly("2000");
> rptBean2.setWeekly("200");
> newA.add(rptBean2);
>
> rtnV.put("FirstWeb", newA);
>
> Vector newB = new Vector();
> ReportBean rptBean3 = new ReportBean();
> rptBean3.setServiceName("Web3");
> rptBean3.setBiweekly("30");
> rptBean3.setYearly("3000");
> rptBean3.setWeekly("300");
> newB.add(rptBean3);
> ReportBean rptBean4 = new ReportBean();
> rptBean4.setServiceName("Web4");
> rptBean4.setBiweekly("40");
> rptBean4.setYearly("4000");
> rptBean4.setWeekly("400");
> newB.add(rptBean4);
>
> rtnV.put("SecondWeb", newB);
>
> Vector newC = new Vector();
>
> ReportBean rptBean5 = new ReportBean();
> rptBean5.setServiceName("Web5");
> rptBean5.setBiweekly("4");
> rptBean5.setYearly("1000");
> rptBean5.setWeekly("10");
> newC.add(rptBean5);
> ReportBean rptBean6 = new ReportBean();
> rptBean6.setServiceName("Web6");
> rptBean6.setBiweekly("20");
> rptBean6.setYearly("2000");
> rptBean6.setWeekly("200");
> newC.add(rptBean6);
>
> rtnV.put("ThirdWeb", newC);
>
> return (rtnV);
> }
>
> but i get the following output:
>
> Report Header
> Vendor Service Biweekly Yearly Weekly
> FirstWeb
> Web2 20 2000 200
>
> SecondWeb
> Web4 40 4000 400
>
> ThirdWeb
> Web6 20 2000 200
>
>
> the items Web1 , web3 , web 5 are missing. I am not able to figure out how to get those in the report. Your comments appreciated.
>
> Thanks.
Re: Layout Problem with Scripted data set with hashmap [message #675903 is a reply to message #675894] Wed, 01 June 2011 17:27 Go to previous message
Ram  is currently offline Ram
Messages: 3
Registered: May 2011
Junior Member
Hi Jason,

Thank you for the prompt answer. I really appreciate your time on this. The example you referred to is what i was looking for. And i did find the complex way to get the report done by using the hashmap size as the starting point, but the solution in your example is much simpler.

Thanks.
Previous Topic:Report Width Formatting Question
Next Topic:Export Data - Available Columns
Goto Forum:
  


Current Time: Wed Jul 23 09:59:38 EDT 2014

Powered by FUDForum. Page generated in 0.04205 seconds