Formatting a double in JSF

会有一股神秘感。 提交于 2019-12-05 01:16:34

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>

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

If what you are trying to do is make the value of the input text field change on screen (to correct user input), you should probably look into using one of the JSF ajax frameworks like Rich Faces.

A possible example would look like this:

<h:inputText id="december" value="#{budgetMB.december}" styleClass="StandardBlack">
  <f:convertNumber maxFractionDigits="2" groupingUsed="false" />
  <a4j:support event="onblur" reRender="december" />
</h:inputText>

I haven't tested this, but I think it may work.

It seems you're actually formatting a currency. There already exists a specific formatter to handle currencies that you can assign many options to:

<f:convertNumber type="currency" />

Some interesting attributes of this tag are: locale, currencyCode, integerOnly, currencySymbol and pattern.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!