Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting a double in JSF

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

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?

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>

EDIT: 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.

like image 425
Stian Avatar asked Oct 03 '08 13:10

Stian


1 Answers

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.

like image 88
Ian McLaird Avatar answered Oct 13 '22 01:10

Ian McLaird