我可以将f:convertNumber与h:outputFormat一起使用吗 [英] Can I use f:convertNumber with h:outputFormat

查看:69
本文介绍了我可以将f:convertNumber与h:outputFormat一起使用吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复合组件,这是它的摘录.

I have a composite component and this is a snippet from it.

<h:outputFormat id="output" value="{0} / {1} / {2}" rendered="#{cc.attrs.readOnly}" styleClass="#{cc.attrs.styleClass}">
    <f:param value="#{empty cc.attrs.value1 ? '-' : cc.attrs.value1}" />
    <f:param value="#{empty cc.attrs.value2 ? '-' : cc.attrs.value2}" />
    <f:param value="#{empty cc.attrs.value3 ? '-' : cc.attrs.value3}"/>
</h:outputFormat>

如果我想使用<f:convertNumber>格式化value3,我该怎么做?

If I want to format value3 using <f:convertNumber>, how can I do that?

推荐答案

<h:outputFormat> uses under the covers standard java.text.MessageFormat API. Go ahead clicking that link and reading the javadoc.

<f:convertNumber> 使用标准的 java.text.NumberFormat API 恰好由MessageFormat支持.正如其javadoc所说,数字模式可以用{[index], number, [pattern]}表示.

<f:convertNumber> uses under the covers the standard java.text.NumberFormat API which happens to be supported by MessageFormat as well. As its javadoc says, numeric patterns can be represented by {[index], number, [pattern]}.

因此,(因此,此示例假定您需要2个固定长度的小数位):

Thus, so (this example assumes that you want 2 fixed-length fraction digits):

<h:outputFormat id="output" value="{0} / {1} / {2,number,#.00}" rendered="#{cc.attrs.readOnly}" styleClass="#{cc.attrs.styleClass}">
    <f:param value="#{empty cc.attrs.value1 ? '-' : cc.attrs.value1}" />
    <f:param value="#{empty cc.attrs.value2 ? '-' : cc.attrs.value2}" />
    <f:param value="#{empty cc.attrs.value3 ? '-' : cc.attrs.value3}"/>
</h:outputFormat>

这篇关于我可以将f:convertNumber与h:outputFormat一起使用吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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