简体   繁体   English

jsf h:inputText和Double值

[英]jsf h:inputText and Double value

I use: 我用:

<h:inputText id="costsPerPallet" value="#{globalReportSelectionForm.palletCost}" size="5">
   <f:convertNumber pattern="0.00"/>
</h:inputText>

palletCost is a Double; trayCost是Double;

When entering a value of "1.00" and submit it is fine. 输入值“ 1.00”并提交时可以。 When I enter "1" and submit I get the error: 当我输入“ 1”并提交时出现错误:

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double

What is a good way to put "1.00" before the submit. 将“ 1.00”放在提交之前的好方法是什么。 In the onblur javascript function? 在onblur javascript函数中? Or is there a better way? 或者,还有更好的方法?

Works fine here on JSF Mojarra 1.2_14 and 2.0.2. 在JSF Mojarra 1.2_14和2.0.2上可以正常工作。 So I think it's a bug in one of the ancient versions and that you need to upgrade your JSF version. 因此,我认为这是其中一个较旧的版本中的错误,您需要升级JSF版本。 You may also try to explicitly convert it as Double as follows. 您还可以尝试如下将其显式转换为Double

<h:inputText converterId="javax.faces.Double">

Not sure if that works though. 不确定是否可以。 Upgrading your JSF impl to latest build is definitely worth it. 绝对值得将JSF impl升级到最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM