Pages

Saturday, October 22, 2011

jasper variable expressions + ireport

Divide by zero error
use of following command in expression allows to eliminate decide by zero error in jasper. $F{feild_name1} and $F{feild_name2} are fields value return from query. if the denominator ($F{feild_name1}) is equal to 0 then command returns 0. Else this returns $F{feild_name2}.doubleValue() / $F{feild_name1}.doubleValue().
new Double(($F{feild_name1}.doubleValue() == 0.00) ? 0.00 : ($F{feild_name2}.doubleValue() / $F{feild_name1}.doubleValue() * 100))
new Double(($F{wave}.toString() == null) ? $F{project} : ($F{project}.toString() + $F{wave}.toString()))

Java servlet use in expression area.
Utils() is the Java class name. com.mycompany.utils is Java package name. filed value is used in Java servlet as a string value and return the output value.
(new com.mycompany.utils.Utils()).hourFormat($F{feild_name2}.toString())
Return current date
use of following  phase in parameter expression area will set set current date as default parameter value.
new java.util.Date()

Return exact date
use of following  phase in parameter expression area will set set "2000- 1- 1" as default parameter value.
new java.util.Date(new GregorianCalendar(2000, 1, 1).getTime().getTime())
If, Elsif and Else condition in Jasper 



new String(($F{project_type}.toString() == "I") ? "IT" :
    (new String(($F{project_type}.toString() == "M") ? "Medical" :
        ((new String(($F{project_type}.toString() == "C") ? "Consumer" :
            ((new String(($F{project_type}.toString() == "X") ? "Other/Dont know" :
            ("- ") )))
                )))
           )
     )
)