Jump to content

Recommended Posts

Posted

I have  a few optional parameters which a user is expected to select a value for before a report is generated.

If a user selects a value,  the report is filtered ( by a where clause) based on the selected parameter criterion, othewise a report with all values for that parameter is presented.

I would like to show the selected parameter in the Title Band . If a user skips a parameter selection, I want to show all in the Title.

The text field element in the Title Band has the  follwing syntax

"Town  - "+ ($P{TOWN_ID}!=null?$F{TOWN_ID}:"All").toString()

However at runtime the report spits out null  if there is no parameter selection by the user, otherwise it works fine.

Would appreciate all/any help.

Thanks!

 

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Posted

1) You do not need use toString() method to display $F{TOWN_ID}. "Town - "+$F{TOWN_ID} should take care of the casting for you (assuming $F{TOWN_ID} is a numeric type). But this is not the reason you are having this problem.

2) Your ternary decision is based on >>> parameter $P{TOWN_ID} <<< value, but you are using >>> field content $F{TOWN_ID} <<< to display the title text. Without knowing your report design and deployment, the only logical conclusion is that report query produces no resultset when skipping $P{TOWN_ID} selection, thus as part of the empty resultset, $F{TOWN_ID} contains nothing but null.

Should you use the following to display parameter $P{TOWN_ID} value in report title band instead?

"Town  - "+($P{TOWN_ID}==null?"All":$P{TOWN_ID})

Posted

Here is a sample report created in the Studio 6.1 and tested in JasperReports Server pro 6.1 - iReport is no longer officially supported and we encourage users to use Jasper Studio instead. The report design approach should be the same regardless which product you are using.

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  --><!-- 2015-07-24T16:25:24 --><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="demo for singhpj" language="groovy" pageWidth="612" pageHeight="792" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3a1a8239-30ef-45f8-9e10-29f6829f5088">    <property name="ireport.zoom" value="1.0"/>    <property name="ireport.x" value="0"/>    <property name="ireport.y" value="0"/>    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JRSrepo"/>    <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>    <property name="ireport.jasperserver.user" value="superuser"/>    <property name="ireport.jasperserver.report.resource" value="/public/TTC/test_null_parm/demo_for_singhpj_files/main_jrxml"/>    <property name="ireport.jasperserver.reportUnit" value="/public/TTC/test_null_parm/demo_for_singhpj"/>    <parameter name="TOWN_ID" class="java.lang.Integer">        <defaultValueExpression><![CDATA[null]]></defaultValueExpression>    </parameter>    <parameter name="ID" class="java.lang.String" isForPrompting="false">        <defaultValueExpression><![CDATA[$P{TOWN_ID}==null?"":" where id = "+$P{TOWN_ID}]]></defaultValueExpression>    </parameter>    <queryString>        <![CDATA[select id as TOWN_ID from jiuser  $P!{ID}]]>    </queryString>    <field name="town_id" class="java.lang.Long"/>    <background>        <band splitType="Stretch"/>    </background>    <title>        <band height="40" splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>            <textField>                <reportElement x="0" y="0" width="572" height="20" forecolor="#000000" uuid="1f4ebaaf-166a-498c-95cf-68bd5e85fbe6"/>                <textFieldExpression><![CDATA["Town  - "+($P{TOWN_ID}==null?"All":$P{TOWN_ID})]]></textFieldExpression>            </textField>            <textField>                <reportElement x="0" y="20" width="572" height="20" forecolor="#FF000D" uuid="363fd15f-f1a6-4f76-af92-40711369ca21"/>                <textFieldExpression><![CDATA["Town  - "+($P{TOWN_ID}==null?"All":$F{town_id})]]></textFieldExpression>            </textField>        </band>    </title>    <pageHeader>        <band splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>        </band>    </pageHeader>    <columnHeader>        <band splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>        </band>    </columnHeader>    <detail>        <band height="20" splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>            <staticText>                <reportElement isPrintRepeatedValues="false" x="0" y="0" width="100" height="20" uuid="e33a6e41-1378-4c73-8dd8-d086fbc697bc">                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>                </reportElement>                <text><![CDATA[town_id]]></text>            </staticText>            <textField>                <reportElement x="100" y="0" width="100" height="20" uuid="23cb1334-fbce-4761-8ae1-72a69baa9ef9">                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>                </reportElement>                <textFieldExpression><![CDATA[$F{town_id}]]></textFieldExpression>            </textField>        </band>    </detail>    <columnFooter>        <band splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>        </band>    </columnFooter>    <pageFooter>        <band splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>        </band>    </pageFooter>    <summary>        <band height="30" splitType="Stretch">            <property name="com.jaspersoft.studio.unit.height" value="pixel"/>            <frame>                <reportElement x="0" y="0" width="200" height="30" uuid="d67d50a3-0037-4ec7-a161-fbe6bb005387">                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>                </reportElement>                <box>                    <topPen lineWidth="0.5" lineStyle="Solid"/>                    <leftPen lineWidth="0.5" lineStyle="Solid"/>                    <bottomPen lineWidth="0.5" lineStyle="Solid"/>                    <rightPen lineWidth="0.5" lineStyle="Solid"/>                </box>                <textField>                    <reportElement x="5" y="5" width="190" height="20" uuid="d1044c22-18e5-4062-87ce-09d439ae3d5e">                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>                        <property name="com.jaspersoft.studio.unit.x" value="pixel"/>                        <property name="com.jaspersoft.studio.unit.y" value="pixel"/>                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>                    </reportElement>                    <textFieldExpression><![CDATA["TOTAL RECORDS: "+$V{REPORT_COUNT}]]></textFieldExpression>                </textField>            </frame>        </band>    </summary></jasperReport>

1-report-all.png.7f23b6d4d8ae782fca2574d4c467bf65.png

2-report-one.png.d80e948b855c6fdf625ce3737e3fc44c.png

3-report-none.png.340f938d6a7230ff83c4af3061c1f62b.png

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...