Jump to content
We've recently updated our Privacy Statement, available here ×

Do parameter field will iterate through the array


neetikamittal

Recommended Posts

Hi Friend,

If I tried to put multiple values against a single key in hashmap.

Whether the parameter defined in Ireport design phase will automatically iterate through those values one by one against that key.

 

I want to have a report like

 

First Name Homephone

Amber 4089874563

Amber 4987654567

Amber 3448768907

 

here all three Amber are different persons.

so I designed a report like this

 

First Name HomePhone

$P{firstname} $P{homephone}

 

and write a code like this

 

PreparedStatement stmt = jdbcConnection.prepareStatement("select firstName, homePhone from person where firstName = ?");

stmt.setString(1,name);

ResultSet rs = stmt.executeQuery();

ArrayList names = new ArrayList();

 

while (rs.next()) {

 

names.add(rs.getString("homePhone"));

}

Object ia[] = names.toArray();

int len=ia.length;

String[] s1=new String[len];

for(int i=0;i<len-1;i++)

{

s1= ia.toString();

 

}

 

hmap.put("homephone",s1);

hmap.put("firstname",name);

 

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,hmap,jdbcConnection);

JRHtmlExporter exporter = new JRHtmlExporter();

Map imagesMap = new HashMap();

req.getSession().setAttribute("IMAGES_MAP",imagesMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);

exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRExporterParameter.OUTPUT_WRITER,out);

exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,Boolean.FALSE);

exporter.exportReport();

 

 

But I think my parameter field is not iterating through the array values that I put in code.

 

So how can I do this thing.

it seems in IREPORT hashmap will take only single value against a key.

Plz let me know as soon as possible.

 

Thanks

Neetika

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

you are 90% of the way there.

 

modify your code and change it to a customdatasource.

 

then instead of doing your rs.next(), and sticking the data into a map.

 

separate it out, and implement a customdatasource with a next() function.

 

each time jasperreports hits a field on the report it will ask your driver for the data.

 

all you need to do is supply the data for that field, the report will do the rest of the work.

Link to comment
Share on other sites

Thanks for ur response.

But till now I am working only with JDBC DataSource.

I don't know wat kind of changes U r trying to say .

Can U explain in detail.

Wat Should I need to do ?

Do u have any example/code snippets for this.

I will be highly obliged.

meanwhile I am trying my best to solve this problem.

Thanks

Neetika

Link to comment
Share on other sites

The only thing the JR engine iterates on is the report data source (/the query result if the report uses a query). If you need to iterate on something else, you have to create a subreport and pass it your data as data source.

 

Why don't you use

Code:
select homePhone from person where firstName = $P{firstname}

as report query and define a "homePhone" field?

 

HTH,

Lucian

Link to comment
Share on other sites

Hi Lucian,

Actually I am trying to have a customized report.

I have a jsp page with one of its field as text field to enter the name of the person which the user wants to see the report.

 

That is why I used prepared statements.

 

My question Is still there.

How can I make my $P{homephone} iterate through the string array value against a single key in hashmap.

 

Amber 32473474232 //these phone nos are in string Array

Amber 23282842234 //hashmap("homephone",s1)

Amber 23278733439 //$P{homephone}should fill these

values one by one

 

 

In Report Design I have

$P{firstname} $P{homephone}

 

 

I already posted the code earlier.

U can have look at it.

 

Thanks

Neetika

Link to comment
Share on other sites

You need to wrap your homephone array into a JRDataSource implementation and pass it to the fillReport() method. As I said earlier, the only thing that gets iterated when a report is filled is its data source.

 

If, in your report, there is something else to iterate on, you should use a subreport to display the home phones.

 

HTH,

Lucian

Link to comment
Share on other sites

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...