Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » how to create a non row based free form report in BIRT(how to create a non row based free form report in BIRT)
how to create a non row based free form report in BIRT [message #709445] Wed, 03 August 2011 23:23 Go to next message
Tuco  is currently offline Tuco
Messages: 6
Registered: August 2011
Junior Member
Hello All,

I have just started using BIRT and somewhat stuck.

I am trying to create a free form report where report should look like

REPORT

Name: Tuco Ramirez Address: {SomeAddress}
Phone#: some no {Probably some static text here}
Some other static Text...


I start to use the scripted datasource and call the Java class in the open script of the dataset.
What my dataset returns is a HashMap containing "identity.FirstName:Tuco", "identity.LastName:Ramirez".

What i need to do is get hold of this map in the report, and assign the value of FirstName, LastName etc to the some variables which i can use in the report.

but i am not sure how to do it..

This is what the open script of the dataset looks like

----open script in dataset

util = new Packages.org.***rest.util.ReportsUtil();
reportsVO = util.getReportVO("ABC");

totalrows = 1;
currentrow = 0;


-----fetch in dataset

if(currentrow < totalrows) {
dataSetRow["FirstName"] = reportsVO.getPropValue("identity.FirstName");
dataSetRow["LastName"] = reportsVO.getPropValue("identity.LastName");

currentrow++;
} else {
return (false);
}

Here's a bit of Java code that just populates the Map and returns..

ReportsUtil.java

package test;

public class ReportsUtil {

public ReportVO getReportVO(String string) {
ReportVO reportVO = new ReportVO();

reportVO.addPropValue("identity.FirstName", "Tuco");
reportVO.addPropValue("identity.LastName", "Ramirez");

return reportVO;
}
}

ReportVO.java

package test;

import java.util.HashMap;
import java.util.Map;

public class ReportVO {

private Map<String, Object> propValuesMap = new HashMap<String, Object>();

public Map<String, Object> getPropValuesMap() {
return propValuesMap;
}

public void setPropValuesMap(Map<String, Object> propValuesMap) {
this.propValuesMap = propValuesMap;
}

public void addPropValue(String propName, Object value) {
propValuesMap.put(propName, value);
}

public Object getPropValue(String propName) {
return propValuesMap.get(propName);
}
}


As a starting point, I am trying to print the firstName and LastName on the report.
How do i get the reference to firstName and lastName on the layout of the report.
I am trying to go to the layout and add a dynamic text? Do i need to add a dynamic text? How do i get reference to the firstName and lastName?

Or If someone could point me to a tutorial for such a non row based report, that would be great...

Thanks a zillion...

Tuco.
Re: how to create a non row based free form report in BIRT [message #710007 is a reply to message #709445] Thu, 04 August 2011 15:18 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

The first thing to get working is your dataset. Is is returning a row
of data? I noticed in your fetch that you do not have return( true )
for the first row. Add it right below currentrow++;

Once it is returning data you can just drag the field into a grid and
this will create data item to show the value. or You can add a grid to
the canvas, select its binding tab in the properties view and bind the
grid to your dataset. Next you can add a data item or text element from
the palette to the grid and set the value. A text element will allow
you to combine your data with other text. So if you go with this
approach you could set the expression for the text element to something
like:

"Customer First Name " +<value-of>row["FirstName"]</value-of>

Make sure to set the type for the text element to HTML in the drop down
box at the top.

BTW scripted datasets also support using Java Objects as data types. I
wrote a blog post on how you can use this. May be of interest to you.
http://birtworld.blogspot.com/2010/10/birt-java-object-data-type.html

Jason

On 8/3/2011 7:23 PM, Tuco wrote:
> Hello All,
> I have just started using BIRT and somewhat stuck.
>
> I am trying to create a free form report where report should look like
>
> REPORT
>
> Name: Tuco Ramirez Address: {SomeAddress}
> Phone#: some no {Probably some static text here}
> Some other static Text...
>
>
> I start to use the scripted datasource and call the Java class in the
> open script of the dataset.
> What my dataset returns is a HashMap containing
> "identity.FirstName:Tuco", "identity.LastName:Ramirez".
>
> What i need to do is get hold of this map in the report, and assign the
> value of FirstName, LastName etc to the some variables which i can use
> in the report.
>
> but i am not sure how to do it..
>
> This is what the open script of the dataset looks like
>
> ----open script in dataset
>
> util = new Packages.org.***rest.util.ReportsUtil();
> reportsVO = util.getReportVO("ABC");
>
> totalrows = 1;
> currentrow = 0;
>
>
> -----fetch in dataset
>
> if(currentrow < totalrows) {
> dataSetRow["FirstName"] = reportsVO.getPropValue("identity.FirstName");
> dataSetRow["LastName"] = reportsVO.getPropValue("identity.LastName");
> currentrow++;
> } else {
> return (false);
> }
>
> Here's a bit of Java code that just populates the Map and returns..
>
> ReportsUtil.java
>
> package test;
>
> public class ReportsUtil {
> public ReportVO getReportVO(String string) {
> ReportVO reportVO = new ReportVO();
> reportVO.addPropValue("identity.FirstName", "Tuco");
> reportVO.addPropValue("identity.LastName", "Ramirez");
> return reportVO;
> }
> }
>
> ReportVO.java
>
> package test;
>
> import java.util.HashMap;
> import java.util.Map;
>
> public class ReportVO {
> private Map<String, Object> propValuesMap = new HashMap<String, Object>();
>
> public Map<String, Object> getPropValuesMap() {
> return propValuesMap;
> }
>
> public void setPropValuesMap(Map<String, Object> propValuesMap) {
> this.propValuesMap = propValuesMap;
> }
> public void addPropValue(String propName, Object value) {
> propValuesMap.put(propName, value);
> }
> public Object getPropValue(String propName) {
> return propValuesMap.get(propName);
> }
> }
>
>
> As a starting point, I am trying to print the firstName and LastName on
> the report.
> How do i get the reference to firstName and lastName on the layout of
> the report.
> I am trying to go to the layout and add a dynamic text? Do i need to add
> a dynamic text? How do i get reference to the firstName and lastName?
>
> Or If someone could point me to a tutorial for such a non row based
> report, that would be great...
>
> Thanks a zillion...
>
> Tuco.
Re: how to create a non row based free form report in BIRT [message #710057 is a reply to message #710007] Thu, 04 August 2011 16:26 Go to previous messageGo to next message
Tuco  is currently offline Tuco
Messages: 6
Registered: August 2011
Junior Member
Thanks Jason for explaining how to create the elements in the layout,

The report is non rows based. It is essentially a free form, lets say a paragraph with some fields that need to be filled.

The final report could be

" The Patient {FirstName} {LastName} ...........some static text..................
..............with phone No {phoneNumber} ...................some other static or dynamic info................
"

So, my dataset returns a HashMap which contains FirstName, LastName, phoneNumber and other fields as keys and their values as corresponding values.

However, the Java code returning the dataset(HashMap is this case) does not know that which fields are in which row....there is only one map which is returned, so i think there is only one call to the dataset...which is why in the code that i mentioned, there was only one call to the Java code.

The field which can be shown in the report will be dynamic, so i am trying to return a Map instead of a Java object.

So, although row["FirstName"] will be valid for the first row, it will not be valid for the second or any other row because the report requires "FirstName" only in the first row. So, i am not sure what should be written in the fetch script.
Probably we could have all the firstName, LastName, phoneNo as parameters and fetch the Map dataset only once, and set the above FirstName, LastName parameters in the fetch script instead of setting the row["FirstName"], row["LastName"] etc. Is there a way to set the value of parameters in the fetch script?


Thanks a lot.

Tuco
Re: how to create a non row based free form report in BIRT [message #710141 is a reply to message #710057] Thu, 04 August 2011 18:45 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

I am a little confused. Even if the report is not row based you can
setup a scripted data set to only return one row and then get all the
values from it. You can also call out to Java from an expression and
not even use a dataset. For example assume you have an object call
MyObject in the package my.test.package. Assume MyObject has a method
that returns first name MyObject.getFirstName(); You can call this
method from a text element like:

"Customer First Name " +<value-of>
importPackage(Packages.my.test.package);
var myobj = new MyObject();
myobj.getFirstName();</value-of>

Jason

On 8/4/2011 12:26 PM, Tuco wrote:
> Thanks Jason for explaining how to create the elements in the layout,
>
> The report is non rows based. It is essentially a free form, lets say a
> paragraph with some fields that need to be filled.
>
> The final report could be
>
> " The Patient {FirstName} {LastName} ...........some static
> text..................
> ..............with phone No {phoneNumber} ...................some other
> static or dynamic info................
> "
>
> So, my dataset returns a HashMap which contains FirstName, LastName,
> phoneNumber and other fields as keys and their values as corresponding
> values.
>
> However, the Java code returning the dataset(HashMap is this case) does
> not know that which fields are in which row....there is only one map
> which is returned, so i think there is only one call to the
> dataset...which is why in the code that i mentioned, there was only one
> call to the Java code.
>
> The field which can be shown in the report will be dynamic, so i am
> trying to return a Map instead of a Java object.
>
> So, although row["FirstName"] will be valid for the first row, it will
> not be valid for the second or any other row because the report requires
> "FirstName" only in the first row. So, i am not sure what should be
> written in the fetch script.
> Probably we could have all the firstName, LastName, phoneNo as
> parameters and fetch the Map dataset only once, and set the above
> FirstName, LastName parameters in the fetch script instead of setting
> the row["FirstName"], row["LastName"] etc. Is there a way to set the
> value of parameters in the fetch script?
>
>
> Thanks a lot.
>
> Tuco
>
Re: how to create a non row based free form report in BIRT [message #710166 is a reply to message #710141] Thu, 04 August 2011 19:17 Go to previous messageGo to next message
Tuco  is currently offline Tuco
Messages: 6
Registered: August 2011
Junior Member
Thanks Jason.

"Customer First Name " +<value-of>
importPackage(Packages.my.test.package);
var myobj = new MyObject();
myobj.getFirstName();</value-of>

which you mentioned indeed works.

Is it possible that i can make only one call to the get the Java object like

"
importPackage(Packages.my.test.package);
var myObject = new MyObject();
HashMap map = new myObject.getMap();
"

And then get all the parameters required by doing map.get("FirstName"), map.get("LastName") etc.

If so, how should it be done?

You mentioned "Even if the report is not row based you can
setup a scripted data set to only return one row and then get all the
values from it."
That was what i was trying to do in the code above code like


----open script in dataset

util = new Packages.org.***rest.util.ReportsUtil();
reportsVO = util.getReportVO("ABC");

totalrows = 1;
currentrow = 0;

-----fetch in dataset

if(currentrow < totalrows) {
dataSetRow["FirstName"] = reportsVO.getPropValue("identity.FirstName");
dataSetRow["LastName"] = reportsVO.getPropValue("identity.LastName");
currentrow++;
} else {
return (false);
}

So, the above fetch should be called only once because the value of currentrow < totalrows only in the first iteration, but there i am setting the value of dataSetRow["FirstName"]. Is it right? I tried to refer to this dataSetRow in the layout using the dynamic text element and changing the property binding to refer to the dataset but it did not show any results..

Can you please help me out in just making one call to the Java code for all the elements and not making multiple calls?

Thanks

Tuco

Re: how to create a non row based free form report in BIRT [message #710178 is a reply to message #710166] Thu, 04 August 2011 19:35 Go to previous message
Tuco  is currently offline Tuco
Messages: 6
Registered: August 2011
Junior Member
Yes, you are right Jason,

I was missing the return true in the dataset fetch script.

if(currentrow < totalrows) {
dataSetRow["FirstName"] = reportsVO.getPropValue("identity.FirstName");
dataSetRow["LastName"] = reportsVO.getPropValue("identity.LastName");
currentrow++;
return true;
} else {
return (false);
}

It works now!!!

Thanks a ton...
Previous Topic:How to access the parameters of report in chart script ?
Next Topic:Hide rows in Cross tab
Goto Forum:
  


Current Time: Sat Oct 25 21:25:52 GMT 2014

Powered by FUDForum. Page generated in 0.02409 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software