jasper report detect if datail band or subreport is present in current page - jasper-reports

I'm developing a report with jasper.
The main report has several subreports.
Only one of these subreport has a fixed text with a note number, something like this.
my text<sup>(2)</sup>
In main report I must print the footnote, but only in all the pages in which the text with the note is present.
An image to better explain:
Is there something that permit to detect if a subreport is present in the current page?
Or something that permit to detect if a detail band is present in the current page?
Or something that permit to detect if a particular text will be printed in current page?
Or other strategy to handle this particular situation?

. Create Variable in main report 'subReportCount'
Type = Integer, default 0
Reset Type = 'Page'
. Place this variable (hidden) somewhere after Subreport
. Create variable 'SubVar' in subreport , expression == $V{REPORT_COUNT}
. In main, go to subreport properties -> Edit return Values - >
Set From Varible= SubVar , To Variable=subReportCount, Calculation type = Sum
. Page Footer Print When Expression = $V{subReportCount} > 0
This may work if you are trying if subreport is printed atleast once in page.

Does not matter if you place subreport variable in report or not.
I tried on my local , its working for similar situation
Variable in Main report
<variable name="subReportCount" class="java.lang.Integer" resetType="Page" incrementType="Page" calculation="Sum">
<variableExpression><![CDATA[$V{subReportCount}.equals( null ) ? 0 : $V{subReportCount}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
Return Value for the subreport
<returnValue subreportVariable="SubVar" toVariable="subReportCount"/>
Print when expression for Footer element, in my case I am showing Page number
<printWhenExpression><![CDATA[$V{subReportCount} > 0]]></printWhenExpression>
This should work , if not please share your jrxml and sample data.
Good Luck!

Related

Start JasperReport subreport on new page, but not when launched as main report

I have a JasperReport named 'Receipt' that can be launched as a:
subreport in a Summary band, to display any receipts
main report, to display a particular receipt
How can I start a new page before any receipts, when it is used as a subreport, but suppress the new page if there are no receipts?
Setting isTitleNewPage="true" works when it is used in the subreport case, but causes the Detail band to be displayed on the second page when it is used as a main report.
Using a Break prior to the subreport means a redundant page is used if there are no receipts.
I solved it by:
Adding a Boolean isSubReport parameter to the report
in the Detail band, adding a Break, with a Print When Expression set to:
$V{PAGE_NUMBER} == 1 && $P{isSubReport}
In the parent report, passing the parameter isSubReport with value TRUE()
Feels like there should be a cleaner solution, but it seems to work.

Print when last row on table Jasper report

I have a report that needs to have an image printed only in the last row of the table of each page.
How can I create my print when expression?
Edit:
Sorry for my poor exemple.
until now, i created this variable
<variable name="rowsOnPage" class="java.lang.Integer">
<variableExpression><![CDATA[$V{rowsOnPage} + 1]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
and i try this print when expression:
$V{rowsOnPage} == $V{REPORT_COUNT}
But this expression print the image in each row of table.
As Petter says, providing an example of what you've tried and how close you've got so far would be helpful.
In the meantime my suggestion is that you add a max rowcount value to your SQL and return this as field in your JRXML as e.g. maxRowNum. With this you could then use a printWhen at the point when $V{REPORT_COUNT} == $F{maxRowNum}
This assumes you have access to the SQL part of your code and can play with this.

Show last page footer before page footer [duplicate]

How do you check to see if the current printed page is actually the last printed page?
I have tried the following:
$V{currentPage}.intValue() == $V{totalNumberOfPages} ?
Boolean.TRUE : Boolean.FALSE
waited for a long time .. but no reply from Stackoverflow...
Anyway i found my solution..
First in your summary band put this line
<printWhenExpression><![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen"))]]></printWhenExpression>
Remember this above line must be only in the summary band of the report.
After that you can compare this parameter at any point of time in your report to find last page number .
For Example
<printWhenExpression><![CDATA[new Boolean(!$V{PAGE_NUMBER}.equals($P{REPORT_PARAMETERS_MAP}.get("LastPageNumber")))]]></printWhenExpression>
With the following Print When Expression the summary band gets printed again:
new Boolean(($P{REPORT_PARAMETERS_MAP}.put(
"LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen")) ||
Boolean.TRUE)
You can also use containskey tot test for the existance of the key:
new Boolean(!$P{REPORT_PARAMETERS_MAP}.containsKey("LastPageNumber"))
Nummeric expressions also work, this expression evaluates to true on every page except the one on which the parameter is set:
new Boolean($P{REPORT_PARAMETERS_MAP}.get("LastPageNumber") < $V{PAGE_NUMBER})
My problem was that I created multiple group footers for several crosstabs at the end of my report, with a constant as the group expression so they get printed only once. By setting the parameter in the first footer I can now finally surpress the column headers without resorting to subreports. Great work!!
Berry.
unfortunately your approach didn't worked for me i dont know why.. there are some stuff about your code that are error-prone like this
<![CDATA[new Boolean($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen"))]]></printWhenExpression>
i think in fact that the Summary Band is called only once but you have a bad programming practice in this because if there is not key associate with the KEY in the MAP it will return null and the you call the method equals on it you would receive NULLPOINTEREXCEPTION but i think not in this case.
you should reverse like this
<![CDATA[new Boolean("dummyPrintWhen".equals($P{REPORT_PARAMETERS_MAP}.put("LastPageNumber",$V{PAGE_NUMBER})))]]></printWhenExpression>
the workaround i used on this question is the following.
1). create a parameter in jasperreports
parameter name="totalRecordsOnReport" class="java.lang.Integer"
2). pass the totals records of your detail as parameter.
HashMap<Object,Object>parameters=....
parameters.put("totalRecordsOnReport",yourDetailRowCount);
i need to print some stuff only in the last page below the detail and i use this code.
component print when expression
$V{REPORT_COUNT}.equals($P{totalRecordsOnReport})
and prints in the last page.

iReport parameter not being informed by field

I am using iReport - my first time using it - and I am trying to make a report that will involve passing a parameter to a subreport. I am not able to get that to work, so I did the following test:
I have a large query that grabs various Fields from my DB - when I preview the report these fields are being pulled and display (over and over, etc., a lot of stuff is being pulled).
I created a new parameter on the main report called "myparam". I made it's default value one of the fields that is being successfully pulled from my DB.
I created a textfield to display this param - the intent being it will echo the field that displays already in my report. If I can get it to do that, I figure I can get it to correctly "plug in" to my subreport.
The issue is - when I preview, I am asked to give the parameter a value - I choose default, which defaults it to the Field I set, which means it should now echo that field (aka I WANT it to echo that field). But it does not echo that field. Instead it just shows null over and over again. Here is a screenshot of what I am talking about
Here is the setup for my report:
Here is proof I've set the default value in my xml:
<parameter name="myparam" class="java.lang.String">
<defaultValueExpression><![CDATA[$F{TCORDERID}]]> </defaultValueExpression>
</parameter>
Here is a snippet of the report which is being generated incorrectly (aka myparam is not getting populated right).
THEY ARE BOTH STRINGS
From my understanding of parameters, they are passed to the report/subreport when it gets created. You have set the default value of the parameter to one of your fields, which has not been populated yet when the report gets generated.
I would suggest adding a simple subreport (which is the reason you want to use parameters anyway), remove the parameter on the main report, and add it to the subreport (with a text field to display it).
Now, add the Parameter to the subreport object in your main report. (This is under the Subreport properties section in iReport.
Name: The name of the Parameter in the subreport.
Expression: The field from your main report that will be passed to the subreport.
So your main report will have the following under the subreport detail:
<subreportParameter name="myparam">
<subreportParameterExpression><![CDATA[$F{TCORDERID}]]></subreportParameterExpression>
</subreportParameter>
And then the Parameter in the subreport:
<parameter name="myparam" class="java.lang.String">
<defaultValueExpression><![CDATA["No result"]]></defaultValueExpression>
</parameter>

Subreport values are not displayed in main report

I have my main report which contains 1 subreport. When I run my main report the subreport values are not displayed in my main report, but when I run my subreport individually I can see the output in PDF format. Can anyone help me in fixing this issue?
First see the connection with right click on the report and click on open subreport if its working then clik on the subreport go to the subreport property and see the parameter passed to the subreport is correct or not if not please pass properly. also see the parameter value required for the subreport is that comming from main report.
Means : if your subreport require account_id = 5 the it must that main report passes the value 5 to the subreport.
You need to call the SubreportProcessingEventHandler and add the datasource.
Step 2: Check the properties of subreport.
If it does not need any parameters from main report. Do not add any.
The path of the repo