我可以将f:convertNumber与h:outputFormat一起使用吗

编程入门 行业动态 更新时间:2024-10-26 16:34:19
本文介绍了我可以将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一起使用吗

本文发布于:2023-10-16 11:42:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497454.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:convertNumber   outputFormat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!