JasperReports: Constant string passed to subreport gets a null value when evalueted with P!{} in the SQL-query-Collection of common programming errors
In short:
I’m passing a constant string to a subreport, but for some reason it gets null
value when it’s used in subreports SQL with the P!{}
syntax.
And in more detail:
I have two almost identical subreports. I would like to use a generic subreport instead of defining each subreport individually. Now I have this subreport that takes a string parameter main_or_side
. The idea is to pass value “main” or “side” to the subreport and then use this in the SQL-query.
In the query the parameter is used this way: SELECT table.P!{main_or_side}_diagnosis ...
and should result for example SELECT main_diagnosis ...
when it’s called with the parameter.
When I preview the subreport in iReports it prompts to ask for the parameter and when I enter “main” or “side” it shows the report fine. Now when I preview the mainreport where I have set it to pass value new String("main")
as side_or_main
-parameter, it’ll return an error:
Unknown column 'table.null_diagnosis' in 'field list'
If I make the query static and add a textField to show the value of main_or_side
it shows the passed value fine. So the value get’s passed to the subreport for sure. How can it be that inside the SQL-query P!{main_or_side}
evaluates to null
?
EDIT:
I was doing some cleanup and renaming to copies of my jrxml-files so I could past snippets here. After I removed few irrelevant elements and did some renaming to make to code match my description it started suddenly working.
The problem persists on the original files. I’ll try to go through the differences compared to the modified files and post here if I find out what was causing the problem.