在JSF中格式化双精度 [英] Formatting a double in JSF

查看:134
本文介绍了在JSF中格式化双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题类似于在这里找到的问题: JSF selectItem标签格式.

I have a problem similar to the one found here : JSF selectItem label formatting.

我想做的是接受一个double作为我的值,并用两个小数位显示它.可以通过简单的方式完成吗?

What I want to do is to accept a double as a value for my and display it with two decimals. Can this be done in an easy way?

我尝试使用,但是似乎应用于发送到服务器的inputText的值,而不是输入字段中的初始值.

I've tried using but that seems to be applied on the value from the inputText that is sent to the server and not on the initial value in the input field.

到目前为止,我的代码:

My code so far:

<h:inputText id="december" value="#{budgetMB.december}" onchange="setDirty()" styleClass="StandardBlack">
    <f:convertNumber maxFractionDigits="2" groupingUsed="false" />
</h:inputText>

上面的代码实际上有效.我被JDeveloper愚弄了,即使我显式重建项目并重新启动嵌入式OC4J服务器,它也没有更新jsp页面.但是,重新启动计算机后,一切都很好.

The above code actually works. I was fooled by JDeveloper that didn't update the jsp page even when I did a explicit rebuild of my project and restarted the embedded OC4J server. However, after a reboot of my computer everything was fine.

推荐答案

如果我不误解您的要求,则可以在呈现视图的过程中使用以下方法实现输入框中的值格式:

If I'm not misunderstanding your requirement, I was able to achieve formatting of the value in the input box during the rendering of the view with:

<h:inputText id="text1" value="#{...}">
    <f:convertNumber pattern="#,###,##0.00"/>
</h:inputText>

我在供应商品牌的Eclipse中使用了Standard Faces组件,因此我假设pattern属性是标准JSF的一部分.

I was using the Standard Faces Components in my vendor-branded Eclipse so I'm assuming the pattern attribute is part of standard JSF.

这篇关于在JSF中格式化双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆