Search code examples
jasper-reports

Replace number with name of months


I have sort of data which contains number.

1,2,3,4,5,6,7,8,9,10,11,12, to represent months.

I want to change it so when I preview the report it shows

January
February
March
April 
May
June
July
August
November
December 

I've tried using replace()

.replace("1", "January")

When I run it, it doesn't work

Any suggestion?


Solution

  • You can use Text Field Expression, Replace $V{Month} with your field Name

    <textfieldexpression class="java.lang.String">
        (
            $V{Month}.equals("1") ? "January" : 
            $V{Month}.equals("2") ? "February" :
            $V{Month}.equals("3") ? "March" :
            $V{Month}.equals("4") ? "April" :
            $V{Month}.equals("5") ? "May" :
            $V{Month}.equals("6") ? "June" :
            $V{Month}.equals("7") ? "July" :
            $V{Month}.equals("8") ? "August" :
            $V{Month}.equals("9") ? "September" :
            $V{Month}.equals("10") ? "October" : 
            $V{Month}.equals("11") ? "November" : "December"
        )
    </textfieldexpression>