2004 IR Help Posted August 20, 2006 Share Posted August 20, 2006 By: Berti - queerest Problem with iterators and variables 2005-01-17 09:55 Hello! I'm having some strange problem using iterators and variables inside a report. A pass an iterator as a parameter. The iterator has the same length as the data source provided to the report. The report has a variable where I put the current value of the iterator in each iteration of the detail section. The problem is that the variable seems to be calculated _twice_ for each iteration (I tested it using some printlns :). This snippet of the report shows the problem: ... <parameter name="ItLista" class="java.util.Iterator"/> <variable name="Variable" class="java.lang.Integer"> <variableExpression> (Integer) $P{ItLista}.next() </variableExpression> <initialValueExpression> new Integer(0) </initialValueExpression> </variable> ... <detail> <band height="12"> <textField> <reportElement x="0" y="0" width="55" height="12"/> <textElement verticalAlignment="Bottom"/> <textFieldExpression class="java.lang.Integer"> $V{Variable} </textFieldExpression> </textField> </band> </detail> ... I did a test and subtituted the variableExpression with this: <variableExpression> new Integer($V{Variable}.intValue() + 1) </variableExpression> and it worked! Does anyone knows what's happening here? Thanks in advance! Alberto Salmeron Moreno alberto.salmeron@gmail.com By: Berti - queerest RE: Problem with iterators and variables 2005-01-20 08:34 Hi, I did some debugging and found out that JasperReports does an estimation of the report variables before calculating its real value. In this estimation the values of all variables used are null, but the parameters aren't null aswell. So if the iterator is a parameter, it is advanced twice per datasource iteration. A workaround for this is storing the iterator in another variable, so when the variables estimation is performed the iterator variable is null, so it won't be advanced. Alberto Salmeró®oreno By: Teodor Danciu - teodord RE: Problem with iterators and variables 2005-01-20 10:15 Hi, What you have seen about JasperReports making an estimate of the report variables is true and it serves for anticipating group ruptures. So you have to have that in mind when working with parameters and variables that alter their value when evaluated. Thank you, Teodor Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now