Jump to content
Changes to the Jaspersoft community edition download ×

passing a array[][] to report...


ktrinad

Recommended Posts

By: Adriana Mestrinelli Paranhos - jasperdri

passing a array[][] to report...

2003-02-12 05:54

Hello...

 

how must I pass an array[][] to my report??

how do I manipulate it inside it??

 

thanx

 

 

 

 

By: Giulio Toffoli - gt78

RE: passing a array[][] to report...

2003-02-12 06:24

The solution is implement a JRDataSource.

Take a look at:

 

http://jasperreports.sourceforge.net/api/dori/jasper/engine/data/JRBeanArrayDataSource.html

 

and

 

http://jasperreports.sourceforge.net/api/dori/jasper/engine/JRDataSource.html

 

Please note that:

1. You can not use directly an array[][], you must incapsulate it in a class that implements a JRDataSource.

2. For now it's not possible use a custom datasource (different from a datasource based on a jdbc resultSet) directly with iReport (but if you need it, you can modify IReportCompiler.java passing, i.e., a class that implements JRDataSource and that will be instanced before pass it to the fill method of jasperreports).

 

I hope this helps you.

 

Giulio

 

 

 

 

 

 

By: Adriana Mestrinelli Paranhos - jasperdri

RE: passing a array[][] to report...

2003-02-12 07:36

sorry, but i didn´t understand anything from your answer....

 

do u have any examples or some thing like that??

 

thanx

 

 

 

 

By: Giulio Toffoli - gt78

RE: passing a array[][] to report...

2003-02-12 08:37

#define I_KNOW_A_BIT_OF_JASPERREPORTS

 

#if I_KNOW_A_BIT_OF_JASPERREPORTS

I suppose that your array[][] store a certain number of rows composed by a certain number of fields.

The problem is: how can I use my two dimensions array as a set of rows composed by a set of columns and pass it to my report ? Jasperreports will automagically understand how my data is organized? The aswer is NO!, you must provide some information. To do this, jasperreports provide an interface to write a class that wrap custom datasource (we can see an array[][] as a custom

datasource).

Therefore you must write some code to create a class that implements the interface JRDataSource and use your array as data.

The JRDataSource interface is very simple. A possible implementation of your class could be something like this:

 

import dori.jasper.*

 

public class JRArrayDataSource implements JRDataSource {

 

Object[][] array;

int row_index=0;

 

public JRArrayDataSource(Object[][] array)

{

this.array = array;

row_index = 0;

}

 

// take the field number X

getFieldValue(JRField jrField)

{

try {

return array[row_index][ Integer.parseInt(jrField.getName()) ];

} catch (Excpetion ex)

{

return null;

}

}

 

// Go to the nex line

boolean next()

{

row_index++;

if (row_index > array.length) return false;

return true;

}

}

 

This class suppose that the field name are "0" "1" "2" ....

 

Giulio

 

#EndIf

 

 

 

 

By: Giulio Toffoli - gt78

RE: passing a array[][] to report...

2003-02-12 08:42

A mistake, row_index must be initalized with a value of -1, so the first call to next bring it to be 0.

 

Giulio

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...