Home » Archived » 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 |
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 |
|
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 |
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 |
|
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
>
|
|
| | |
Goto Forum:
Current Time: Thu Sep 19 05:05:44 GMT 2024
Powered by FUDForum. Page generated in 0.04684 seconds
|