2
votes

I'm having an issue with iReport using subreports, I'm using a XML source.

XML SOURCE

<bordereaux>
    <bordereau>
        <pages>
            <page>
                <numpage>1</numpage>
                <dosimetres>
                    <dosimetre>
                        <information>information</information>
                    </dosimetre>
                    <dosimetre>
                        ...
                    </dosimetre>
                    <dosimetre>
                        ...
                    </dosimetre>
                </dosimetres>
            </page>
            <page>
                ...
            </page>
            <page>
                ...
            </page>
            <page>
                ...
            </page>
        </pages>
    </bordereau>
    <bordereau>
        ...
    </bordereau>
    <bordereau>
        ...
    </bordereau>
<bordereaux>

Problem description

My main report is iterating on the < bordereau > nodes.
A subreport (in the main report) is iterating on the < page > nodes, with a page break in the bottom of the "Detail section".
(A subsubreport in the subreport if iterating on each < dosimetre > node, but it's not important in my problem)

What I need to do is, in the "Page Footer" section of my main report, show the value of the < numpage > node.

What I did

I added 1 variable named "numPage" on each report, both are java.lang.String

  • The one on my subreport has for "Variable Expression" $F{numpage}.

  • The one on my main report is linked to the first one by my subreport in the "Return Values" property

What I get

My main report is nicely iterating on my < bordereau > node
My subreport is nicely iterating on my < page > node
If I print the $F{numpage} field in my subreport, I can see it.
If I print the variable $V{numPage} in my subreport, I can see it.

BUT if I print the variable $V{numPage} in my main report, I can only see it's value for the last "< page > node iteration", otherwise I get a nice and smooth "null"

I don't know what to do ... I tried to play with the "Reset type" of the variables, to play with the "Evaluation time" of textfields. But every try was effectiveless ...

See you

I hope I explained my problem nicely, I'm not a native english speaker, so I'm apologising for the bad english ... My english is bad ... and I should feel bad !

Thanks a lot for any help.

Nicolas

2

2 Answers

0
votes

Are you trying to achieve page numbers? If yes, you can simply drop a page number field from the iReport palette in the main report's page footer.

1
votes

I know this was asked a while a go but I have a similar problem. I am trying to get the return value of various sub reports so I can update a "reference" in the footer.

I believe this is because the "return values" from the sub-report are only returned when the whole sub-report has finished, so the variables are not available until then.

I haven't yet found a way around this, and have experimented with reset types, calculation types and evaluation times.

Edit The only solution I have found to this problem is to create a custom scriptlet. You can pass the scriptlet through to sub-reports. The same instance of the class is passed through to the sub-reports, so you can set and retrieve values at any time throughout building the template.

To call a method in the scriptlet, from the sub-report, I defined a variable in the sub-report and in the expression I did something like $P{SCRIPTLET}.setString("foo"). The setString method had to return a String so that the variable could be set, you can then call another method in the master report $P{REPORT_SCRIPTLET}.getString() to get the value at any time.