Jasper report with optional parameter has no pages

I have a Jasper report with a optional parameter $P!{withVessel} that is used in the report query.:

SELECT
     tckopf."VONNAME" AS tckopf_VONNAME,
     tckopf."ANNAME" AS tckopf_ANNAME,
     tckopf."SCHIFF" AS tckopf_SCHIFF,
     tckopf."VON" AS tckopf_VON,
     tckopf."BIS" AS tckopf_BIS,
     tckopf."TAGE" AS tckopf_TAGE,
     tckopf."ID" AS tckopf_ID,
     tckopf."PERIODE" AS tckopf_PERIODE,
     tckopf."BEZAM" AS tckopf_BEZAM
FROM
     "tckopf" tckopf
WHERE
     tckopf."ANMAND"= $P{customerNo}  AND tckopf."VONMAND"= $P{clientNo} $P!{withVessel}

withVessel is defined as java.lang.String with the following “Default Value Expression”.:

$P{vesselNo} == null ? "" : " and tckopf.VESSEL_NR=' "+ $P{vesselNo} + " ' "

The parameter vesselNo is defined as java.lang.Integer and is used as prompt in iReport.

If I compile the report in iReport with and without a passed vesselNo, the report is showed as desired. But if I run the report from Servoy, it is only showed as desired if the vesselNo is not passed to the report. If I pass the vesselNo to the report, I get a message.:

The document has no pages

This is the code that calls the report.:

	reportParams.clientNo = forms.boss_char_charterfaktura_base_dtl.vonmand;
	reportParams.customerNo = forms.boss_char_charterfaktura_base_dtl.anmand;
	if ( withVessel ) {
		reportParams.vesselNo = forms.boss_char_charterfaktura_base_dtl.vessel_nr;
	} else {
		reportParams.vesselNo = null;
	}

	report = plugins.jasperPluginRMI.runReport( db.DATABASE.BOSS_DB, charterFakturaDocListReport, null, "view", reportParams, forms.boss_char_charterfaktura_base_dtl.getDocumentLanguage( ) );

iReport version: 4.0.1
Servoy JasperReports Plugin version: 4.0.1

Why it does not work if I pass the vesselNo to the report from Servoy?

Try this:

SELECT
     tckopf."VONNAME" AS tckopf_VONNAME,
     tckopf."ANNAME" AS tckopf_ANNAME,
     tckopf."SCHIFF" AS tckopf_SCHIFF,
     tckopf."VON" AS tckopf_VON,
     tckopf."BIS" AS tckopf_BIS,
     tckopf."TAGE" AS tckopf_TAGE,
     tckopf."ID" AS tckopf_ID,
     tckopf."PERIODE" AS tckopf_PERIODE,
     tckopf."BEZAM" AS tckopf_BEZAM
FROM
     "tckopf" tckopf
WHERE
     tckopf."ANMAND"= $P{customerNo}  AND tckopf."VONMAND"= $P{clientNo} 
     AND (tckopf.VESSEL_NR=$P{vesselNo} OR $P{vesselNo} IS NULL)

jasantana:
Try this:

SELECT
 tckopf."VONNAME" AS tckopf_VONNAME,
 tckopf."ANNAME" AS tckopf_ANNAME,
 tckopf."SCHIFF" AS tckopf_SCHIFF,
 tckopf."VON" AS tckopf_VON,
 tckopf."BIS" AS tckopf_BIS,
 tckopf."TAGE" AS tckopf_TAGE,
 tckopf."ID" AS tckopf_ID,
 tckopf."PERIODE" AS tckopf_PERIODE,
 tckopf."BEZAM" AS tckopf_BEZAM

FROM
“tckopf” tckopf
WHERE
tckopf.“ANMAND”= $P{customerNo} AND tckopf.“VONMAND”= $P{clientNo}
AND (tckopf.VESSEL_NR=$P{vesselNo} OR $P{vesselNo} IS NULL)

Thanks, your solution does it. :) Do you know, why the other does not work?

Print in the report the value for $P{vesselNo} I guess the only reason not to work is that it has a value which is not null

Thank you jasantana, you save me from the madness, I had the same problem and I was just going crazy with it … Your solution works perfectly fine.