Jaspersoft BI Tools

iReport,Jaspersoft Design Studio,Jaspersoft Server, Schema Workbench,Analysis,Dashboards, Self Service BI, Domains,Topics,Ad-Hoc Reports, Jaspersoft ETL, Embedding BI,HTML-5 charts, Fusion Charts,JFree Charts,Drill down reports , Drill down Dashboards,Visualize.js, Performance Tuning, D3 Charts, Jaspersoft Customization

Wednesday, October 14, 2015

TIP : Get Prvious and Next Months month Names in Jasper Reports

Hi guys,


# Add below code to JRXML <import value="org.apache.commons.lang.time.*"/>
# Take a parameter lets say "Date" and its type as "java.util.Date"
# Default value expression : new Date()

# D



JRXML (Works only in Professional Jasper Studio )

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  -->
<!-- 2015-10-14T15:27:28 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Get Prvious and Next Months month Names" pageWidth="590" pageHeight="842" columnWidth="550" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="586bcdf6-d4c0-4e91-b47f-552a90f90619">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <import value="org.apache.commons.lang.time.*"/>
    <parameter name="Date" class="java.util.Date">
        <defaultValueExpression><![CDATA[new Date()]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="150" splitType="Stretch">
            <textField>
                <reportElement mode="Opaque" x="160" y="30" width="390" height="30" backcolor="#EDF7FF" uuid="e65ee664-6d00-4776-8a31-d2014241ebec"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{Date}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="160" y="60" width="390" height="30" backcolor="#EDF7FF" uuid="31f2ad0a-7a43-474c-8827-6e0adedd0cc0"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new SimpleDateFormat("MMM").format(DateUtils.addMonths($P{Date},-1))]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="0" y="30" width="160" height="30" backcolor="#EDF7FF" uuid="5fa38ea6-0449-4ebf-b669-4034169caa26"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Current Date"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="0" y="60" width="160" height="30" backcolor="#EDF7FF" uuid="4f56f7e3-f84b-4aa6-a83f-c3ed7151711f"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Current Month - 1"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="0" y="90" width="160" height="30" backcolor="#EDF7FF" uuid="129247b7-38f0-4d71-8429-697723aff783"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Current Month + 0 "]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="160" y="90" width="390" height="30" backcolor="#EDF7FF" uuid="5f91c64b-8d22-41b9-9448-b2285471f871"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new SimpleDateFormat("MMM").format(DateUtils.addMonths($P{Date},0))]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="0" y="120" width="160" height="30" backcolor="#EDF7FF" uuid="f55b5d8c-da33-4b37-8345-b8d60d4682c4"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Current Month + 1 "]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="160" y="120" width="390" height="30" backcolor="#EDF7FF" uuid="1745467e-740c-4863-821b-cd46041cbf95"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement verticalAlignment="Middle">
                    <font fontName="Calibri" size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[new SimpleDateFormat("MMM").format(DateUtils.addMonths($P{Date},1))]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement mode="Opaque" x="0" y="0" width="550" height="30" forecolor="#180566" backcolor="#EDE8E8" uuid="4442c4ba-1214-4042-afc8-072027105db2"/>
                <box leftPadding="10">
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font fontName="Calibri" size="20" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA["Get Prvious and Next Months month Names"]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>