Print when last row on table Jasper report - jasper-reports

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.

Related

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

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!

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.

Can I change the value of a variable?

I'm new to JasperReports, but I kind of feel like I'm getting it. After all it is just another mark-up language.
My scenario is that I have a table of data, with the date and some other text columns, and I want to to display a subtotal for each section of the data based on a date. I am expecting zero, one, or many dates to be in the table.
I have a variable defined that calculates the sum of the rows, but I want to reset the sum to zero with each sub-group, is it possible?
Here is my Variable declaration:
<variable name="G_COUNT" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[(($F{ROW_NUMBER}.intValue() != 9)?$F{ITEM_COUNT}:new Integer(0))]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
Is there a way I can use this variable, resetting to 0 when a new date is found, or am I using the wrong type to do what I want?
As a caveat, I am editing the .jrxml file in a text editor, not iReport.
What I was able to figure out from reading the dtd is that groups are available to trigger a reset event.
<variable name="G_COUNT" class="java.lang.Integer" calculation="Sum" resetType="Group" resetGroup="SubCalc">
<variableExpression><![CDATA[(($F{ROW_ORDINAL}.intValue() != 9)?$F{ITEM_COUNT}:new Integer(0))]]></variableExpression>
<initialValueExpression><![CDATA[new Integer(0)]]></initialValueExpression>
<group name="SubCalc">
<groupExpression><![CDATA[$F{ROW_ORDINAL} == 1]]></groupExpression>
</group>
So when the ROW_ORDINAL == 1 it triggers a reset event, which sets the value of G_COUNT to the initialValueExpression

JasperReport table column sum for page

I need TO add a column sum to column footer of table object for each page.
If I create variable and set sum aggregation function than sum value appear for full report. But I need sum column data for each page, not for full report.
Can anyone help me solve this problem?
This is not a solution for the jr:table component since it uses a subdataset where its not allowed to set resetType="Page", but using a subreport it can be used.
I don't think there is a work around in components (jr:table,jr:list) using a subdataset but would be happy If someone can prove me wrong
Solution using subreport
On your variable set resetType="Page"
es.
<variable name="var" class="java.lang.Double" resetType="Page" calculation="Sum"/>
....
</variable>
For more info on resetType see JRVariable API
On your textField set evaluationTime="Page"
es.
<textField evaluationTime="Page">
....
</textField>
For more info on evaluationTime see JRTextField API
In case of Dataset set resetType="Report"

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>