outputFormat一起使用吗

outputFormat一起使用吗

本文介绍了我可以将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> 在标准 java.text.MessageFormat API .继续单击该链接并阅读javadoc.

<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一起使用吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:28