Thursday, April 21, 2011

Jasper reports - iReport - page number variable doesn't work.

I have to prepare a letter in which i require a 40 mm page header for first page and 20mm page header for all other pages except the first page. So I've created 2 page headers. I want to hide/show the page headers based on the page number. But when I write the following print when expression, it doesn't work. $V{PAGE_NUMBER}.equals ("1"). Please help.

From stackoverflow
  • You need to check what the type of $V{PAGE_NUMBER} is... (I think it is java.lang.Integer)

    The method you choose return a boolean an a PrintWhenExpression should return a java.lang.Boolean, so you need to instantiate one.

    Try :

    new Boolean($V{PAGE_NUMBER}.equals("1"))
    

    It should work... To improve your test, I think that it is better to make a int comparison (a Java specialist should confirm that)

    new Boolean($V{PAGE_NUMBER}.intValue() == 1)
    

    The other manipulation you might have to do is specifying the whole object name (I don't know how JasperReport deals with import)

    new java.lang.Boolean($V{PAGE_NUMBER}.intValue() == 1)
    
  • Thanx! The last option work perfectfor me!

    Bozho : use comments, not answers. and mark the answer as accepted, if it worked for you

0 comments:

Post a Comment