PHP array for $X{IN, column, Parameter}

0

Hi,

I'm new to jasper reports. I have created a simple report where data is extracted from a mysql database. No problem.
But when I try to pass parameters to the report where a I want to filter the data with a IN clouse, I allways get all results or an error.

This is my code:

$controls = array('Parameter_1' => array('ANT' => 'ANT', 'LIE' => 'LIE'));                  
$report = $client->runReport('/reports/Test/Formulier_0', 'pdf', null, $controls);
 
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=report.pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . strlen($report));
header('Content-Type: application/pdf');
 
But with this code the full report is given instead of the filtered report
When I change the array into $controls = array('Parameter_1' => array( 'ANT',  'LIE'));
I get an error "Invalid type java.lang.String for parameter Parameter_1 used in an IN clause; the value must be an array or a collection."
 
This is the report dataset:
 
SELECT vzvb.cms_clubs.club_id,
vzvb.cms_clubs.club_naam,
vzvb.cms_clubs.club_nr,
vzvb.cms_clubs.club_province
FROM vzvb.cms_clubs
where $X{IN,  vzvb.cms_clubs.club_province, Parameter_1} 
ORDER BY vzvb.cms_clubs.club_province ASC,
vzvb.cms_clubs.club_naam ASC
 
Parameter_1 is defined as a java.lang.String
 
What am I doing wrong?
 
Thanks in advance.
 
Regards,
 
Bart
bartv2000's picture
Joined: Aug 31 2012 - 2:17am
Last seen: 3 years 11 months ago

1 Answer:

0

I think you gave the answer yourself, you said ' Parameter_1 is defined as as java.lang.String'  and the error sais: ' Invalid type java.lang.String for P1 (..) value must be an array or a collection.' 

Can you try to change you parameterer type (can be found in properties of your param) to 'java.util.ArrayList' or 'java.util.Collection'. 

That should work, and if you only use Strings in the array/collection, you can define 'Nested subtype'  to 'java.lang.String' so you don't have to define the type as well on each object.

Can you let me know if it worked? 

gert_1's picture
200
Joined: Aug 7 2014 - 12:25am
Last seen: 3 years 12 months ago

Hi Gert_1

I created a new report where I needed this and now it works.
I think that the php array I was passing in the parameter was malformed or wrong...

Thank you for the hint.

Regards

bartv2000 - 4 years 10 months ago

Hi bartv2000,

No problem, glad to be helpful.Can you mark this answer as solution/ this topic as answered?

Regards,

gert_1 - 4 years 10 months ago
Feedback
randomness