views:

258

answers:

1

I am creating a jasper report.In that I want to write one method which takes integer and does some process and returns a string.I dont know how to write methods in jasper report.Is it possible to write?Can any one help me in this

I am using iReport3.6.0.

Sample code :

 <textField>
  <reportElement x="400" y="10" width="80" height="15"/>
  <textElement textAlignment="Left" verticalAlignment="Middle"/>
  <textFieldExpression     class="java.lang.String">
               <![CDATA[$F{intValue}]]>
  </textFieldExpression>
 </textField>

In the above code "$F{intValue}" returns integer.I want pass that to one method and that methods return type wants to be string.

Thanks

+2  A: 

Write a helper Java class with a static method that will receive the integer argument and return desired outcome:

package com.yourname.reports.util;

public class JrUtils {
  public static String intFormatter(int arg) {
    return "Beautified int: " + arg;
  }
}

Add this class to the classpath used for compiling jasperreports template and for the runtime. In the iReport right click on report's title in 'Report Inspector' view and choose 'Properties'. Scroll down to 'Imports' and add your class:

com.yourname.reports.util.JrUtils

Add import Java class to your report and invoke the static method from the field using:

<![CDATA["Transformed int: " + JrUtils.intFormatter($F{intValue}) ]>
Boris Pavlović
Thanks...Works good...
BlackPanther
you are welcome
Boris Pavlović