2013-02-21 58 views
0

錯誤:在類型MyExchangeClass方法exchangeConversion(字符串,字符串,浮點型)是不適用的參數(字符串,字符串,雙)如何將float arg傳遞給自定義EL函數(jsp)?

代碼在JSP文件中,錯誤15.4和15.4f以及,如果更改函數和雙重TLD的工作正常。爲什麼15.4和15.4f就好像是雙打?因爲這是指定按如下EL specification在TLD

<function> 
    <name>exchange</name> 
    <function-class>mypackage.MyExchangeClass</function-class> 
    <function-signature>float exchangeConversion(java.lang.String, java.lang.String, float)</function-signature> 
    </function> 

代碼的Java類 公共類MyExchangeClass {

public static float exchangeConversion(String from, String to, float amount) { 
     float calculatedAmount = 0.0f; 

     /* Example implementation code: */ 
     if(from.equals("GBP") && to.equals("USD")) { 
      calculatedAmount = amount*1.5f; 
     } 
     return calculatedAmount; 
    } 
} 

回答

0

... 
From GBP to USD: ${ elfuncs:exchange("GBP", "USD", 15.4f) } 
Otherwise: ${ elfuncs:exchange("GBP", "YEN", 15.4) } 

代碼。浮點文字總是被解釋爲double

1.3 Literals

There are literals for boolean, integer, floating point, string, and null in an evalexpression.

...

  • Floating point - As defined by the FloatingPointLiteral construct in Section 1.19.

1.19 Collected Syntax

...

  • The value of a FloatingPointLiteral ranges from Double.MIN_VALUE to Double.MAX_VALUE .

在功能只需更改floatdouble

+0

所以,你說什麼。在EL函數中使用float作爲參數是不可能的,不是嗎? ■如果A或B是包含。,e或E的浮點型,雙精度型或字符串: - 如果A或B爲BigInteger,則強制A和B都爲BigDecimal並應用 運算符。 - 否則,強制A和B加倍並應用運算符 – Joe 2013-02-21 13:35:48

相關問題