2012-05-03 25 views
1

我在報告中有3個參數。我想在我的TextField中的描述中轉換所有的id參數。如果參數在Jasper報告的TextField中有三個以上的參數,將參數轉換爲描述

The first parameter is $P{address} 
if $P{address} = 1 then "Port Garden" 
else if $P{address} = 2 then "pangsa maju,indah" 
else if $P{address} = 3 then "eastern mouth" 
else null 

The second parameter is the $P{city} 
if $P{city} = 1 then "Gosa" 
else $P{city} = 2 "Marang" 
else if $P{city} = 3 "kuala seberang" 
else null 

The third parameter is the $P{country} 
if $P{country} = 198 then "China" 
else if $P{country} = 234 then "Bangladesh" 
else if $P{country} = 390 then "Sri Lanka" 
else null 

當我輸入參數時,我想要改變文本字段中描述的所有參數。

For example. "Information for company the address is $P{address}=1, city is $P{city}=1 and country is $P{country}=198". 
The result is "Information for the company address is Port garden, city is Gosa and country is China. 

任何人都知道這件事?:(

回答

1

硬編碼的值到報告中這樣爲奇數。這可能是一個壞主意。

但是,儘管是一個壞主意.. 。這並不難做到使用這樣的事情創建一個名爲$ P {COUNTRY_NAME}參數使用三元運算符(多次)這樣給它一個默認值:。

$P{country}==198 ? "China" : 
    $P{country}==234 ? "Bangladesh" : 
    $P{country}==390 ? "Sri Lanka" : "somewhere else" 
+0

我有嘗試的解決方案,但它不起作用。你可以eck我的代碼有什麼問題?:( –

+0

$ P {Country_Name}在我的示例中具有基於$ P {country}的默認值。您有$ P {pd_id}指其自身的默認值。這不起作用。 – mdahlman

+0

我不明白你是什麼意思爲$ P {Country_Name}和$ P {country} ?.即時通訊如此混亂。爲什麼你把2參數。我只想要一個參數和一個描述。怎麼做?可以告訴我更多example.can你修改我的代碼,以便我知道我的錯誤在哪裏? –