Pojo's and a scripted subreport [message #84940] |
Thu, 27 October 2005 15:39  |
Eclipse User |
|
|
|
I am trying to create a sub-report using a scripted data source. I am having
trouble understanding how I should write the scripts of my sub-report so
that the data in my sub-report relates to the parent report.
I am getting my scripted POJO but when I generate the report, I'm getting
the same sub-report data with each parent entry.
I am currently creating a table for the parent report with two detail lines.
In the second detail line I create a second table for my sub-report. For
sake of example and to keep it simple, lets say my POJO looks like this:
public class Pojo {
private String company ;
private Set employees ;
public String getCompany() {
return company ;
}
public Set getEmployees() {
return employees;
}
}
I have two data sets, scriptSet1 and scriptSet2. The parent report Table is
tied to scriptSet1 and the sub-report is tied to scriptSet2. In scriptSet1 I
have defined scripts for open and fetch.
The open looks like this:
df = new Packages.my.package.com.DataFactory();
pojoSet = df.getPojoSet() ;
i = pojoSet.iterator();
The fetch looks like this:
if ( !i.hasNext() ){
return false ;
}
var pojo = i.next();
row["Company"] = pojo.getCompany() ;
j = pojo.getEmployees().iterator() ; // I have tried this in the open of
scriptSet2 but have the same result.
return true ;
My scriptSet2 has a fetch statement that looks as follows:
if ( !j.hasNext() ){
return false ;
}
employee = j.next();
row["Name"] = employee.getName() ;
return true ;
When executing this report, I will get the employees for my last Company
printed for all companies. I am assuming I've overlooked some basic concept.
Any suggestions would be appreciated.
Thanks
|
|
|
|
|
Re: Pojo's and a scripted subreport [message #85187 is a reply to message #85003] |
Fri, 28 October 2005 08:25   |
Eclipse User |
|
|
|
In my haste to leave work yesterday, I should have looked at my data closer.
I still have the same problem.
I've ran several test on my POJO access and the data appears to returning
correctly, however, I am still getting the same sub-report data for each
main report item.
"Tom Stave" <tstave@bmtcarhaul.com> wrote in message
news:djrfjp$1na$1@news.eclipse.org...
> That did the trick -- Thanks
>
> "Jason Weathersby" <jweathersby@actuate.com> wrote in message
> news:djreca$vqt$1@news.eclipse.org...
> > Tom,
> >
> > When you put
> > j = pojo.getEmployees().iterator()
> > in the data set 2 open, did you make pojo global?
> > pojo = i.next();
> > in dataset 1?
> > This looks like it should work.
> >
> > Jason Weathersby
> > BIRT PMC
> >
> >
> >
> > "Tom Stave" <tstave@bmtcarhaul.com> wrote in message
> > news:djraau$q97$1@news.eclipse.org...
> > >I am trying to create a sub-report using a scripted data source. I am
> > >having
> > > trouble understanding how I should write the scripts of my sub-report
so
> > > that the data in my sub-report relates to the parent report.
> > >
> > > I am getting my scripted POJO but when I generate the report, I'm
> getting
> > > the same sub-report data with each parent entry.
> > >
> > > I am currently creating a table for the parent report with two detail
> > > lines.
> > > In the second detail line I create a second table for my sub-report.
For
> > > sake of example and to keep it simple, lets say my POJO looks like
this:
> > >
> > > public class Pojo {
> > > private String company ;
> > > private Set employees ;
> > >
> > > public String getCompany() {
> > > return company ;
> > > }
> > > public Set getEmployees() {
> > > return employees;
> > > }
> > > }
> > >
> > > I have two data sets, scriptSet1 and scriptSet2. The parent report
Table
> > > is
> > > tied to scriptSet1 and the sub-report is tied to scriptSet2. In
> scriptSet1
> > > I
> > > have defined scripts for open and fetch.
> > >
> > > The open looks like this:
> > >
> > > df = new Packages.my.package.com.DataFactory();
> > > pojoSet = df.getPojoSet() ;
> > > i = pojoSet.iterator();
> > >
> > > The fetch looks like this:
> > >
> > > if ( !i.hasNext() ){
> > > return false ;
> > > }
> > > var pojo = i.next();
> > > row["Company"] = pojo.getCompany() ;
> > > j = pojo.getEmployees().iterator() ; // I have tried this in the open
of
> > > scriptSet2 but have the same result.
> > > return true ;
> > >
> > > My scriptSet2 has a fetch statement that looks as follows:
> > >
> > > if ( !j.hasNext() ){
> > > return false ;
> > > }
> > > employee = j.next();
> > > row["Name"] = employee.getName() ;
> > > return true ;
> > >
> > > When executing this report, I will get the employees for my last
Company
> > > printed for all companies. I am assuming I've overlooked some basic
> > > concept.
> > > Any suggestions would be appreciated.
> > > Thanks
> > >
> > >
> >
> >
>
>
|
|
|
|
|
Re: Pojo's and a scripted subreport [message #85415 is a reply to message #85310] |
Fri, 28 October 2005 13:30  |
Eclipse User |
|
|
|
Thanks Jason!
Using a variation of your comments and my earlier example I came up with the
following which seems to work.
I created a new output variable in my scriptSet1 of type ANY and named
"StoreSet". I only use it for storage, I won't display it.
I kept my open for scriptSet1 the same, but I added the following to the
fetch statement:
row["StoreSet"] = pojo.getEmployees() ;
So the fetch looks like this:
if ( !i.hasNext() ){
return false ;
}
var pojo = i.next();
row["StoreSet"] = pojo.getEmployees() ;
row["Company"] = pojo.getCompany() ;
return true ;
When displaying my company name, using expression builder I added the
following:
empSet = row["StoreSet"];
row["companyname"];
My scriptSet2 fetch remains the same, but the open looks like this:
j=empSet.iterator() ;
This appears to work. But if I've thought that before. So if you see
anything I missed please let me know. If not, I hope this helps someone
else.
Thanks again.
"Jason Weathersby" <jweathersby@actuate.com> wrote in message
news:djtgmh$fen$1@news.eclipse.org...
> Tom,
> I did a little more digging on this one.
> This isssue is that Data Set1 gets read completely before doing Data Set
2.
> So this line j = pojo.getEmployees().iterator() will alway return the
last
> one.
> What would be ideal to do is have a method in the pojo that accepts the
> company name as a parameter and returns a Set. Then in the outer table in
> one of the data controls set its value to something like this in the
> expression builder for a data control.
>
> tmptest = row["companyname"];
> row["companyname"];
>
> This will display the company name and set the tmptest variable to the
> company name.
> Then in the open method of Data Set 2 make your call like.
>
> j = pojo.getEmplyforCompany(tmptest).iterator();
>
> I am attaching an example that does something similar with two scripted
ds.
> Look at open and fetch on both DS. Also look at the Expression builder
for
> the data control under OuterCount.
>
> Hope this helps
>
> Jason Weathersby
> BIRT PMC
>
>
>
>
>
> "Tom Stave" <tstave@bmtcarhaul.com> wrote in message
> news:djraau$q97$1@news.eclipse.org...
> >I am trying to create a sub-report using a scripted data source. I am
> >having
> > trouble understanding how I should write the scripts of my sub-report so
> > that the data in my sub-report relates to the parent report.
> >
> > I am getting my scripted POJO but when I generate the report, I'm
getting
> > the same sub-report data with each parent entry.
> >
> > I am currently creating a table for the parent report with two detail
> > lines.
> > In the second detail line I create a second table for my sub-report. For
> > sake of example and to keep it simple, lets say my POJO looks like this:
> >
> > public class Pojo {
> > private String company ;
> > private Set employees ;
> >
> > public String getCompany() {
> > return company ;
> > }
> > public Set getEmployees() {
> > return employees;
> > }
> > }
> >
> > I have two data sets, scriptSet1 and scriptSet2. The parent report Table
> > is
> > tied to scriptSet1 and the sub-report is tied to scriptSet2. In
scriptSet1
> > I
> > have defined scripts for open and fetch.
> >
> > The open looks like this:
> >
> > df = new Packages.my.package.com.DataFactory();
> > pojoSet = df.getPojoSet() ;
> > i = pojoSet.iterator();
> >
> > The fetch looks like this:
> >
> > if ( !i.hasNext() ){
> > return false ;
> > }
> > var pojo = i.next();
> > row["Company"] = pojo.getCompany() ;
> > j = pojo.getEmployees().iterator() ; // I have tried this in the open of
> > scriptSet2 but have the same result.
> > return true ;
> >
> > My scriptSet2 has a fetch statement that looks as follows:
> >
> > if ( !j.hasNext() ){
> > return false ;
> > }
> > employee = j.next();
> > row["Name"] = employee.getName() ;
> > return true ;
> >
> > When executing this report, I will get the employees for my last Company
> > printed for all companies. I am assuming I've overlooked some basic
> > concept.
> > Any suggestions would be appreciated.
> > Thanks
> >
> >
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04398 seconds