4 Replies Latest reply on Apr 12, 2011 11:28 AM by ginni machamer

    Display Integer as currency?

    ginni machamer Newbie

      I have a JSF displaying Integer data types. I want to display the amounts formatted as currency, but assure when the form is submitted that only Integers are submitted.

      I tried adding the f:convertNumber tag, but it does nothing at all.  What is the right way to do this?  If the amount in record.amount is 1000, I want to display $1,000, but when the form is submitted, it must be only 1000 that is submitted.  Thanks!


      <h:inputText value="#{record.amount}">

      <f:convertNumber type="currency"/>








        • 1. Re: Display Integer as currency?
          Pavol Pitonak Master



          in my opinion, f:convertNumber is exactly what you need.



          <h:outputLabel for="currency" value="currency" />
          <h:inputText id="currency" value="#{minBean.value}" label="currency">
              <f:convertNumber type="currency" currencySymbol="€" locale="sk" />


          My code above renders as follows:




          • 2. Display Integer as currency?
            ginni machamer Newbie

            What is the datatype of your minBean.value? Mine is Integer.  I tried exactly what you have there (with Symbol $) and it is not converted. the Integer 1000 shows just as that, 1000, not $1,000.

            • 3. Display Integer as currency?
              Pavol Pitonak Master

              I tried it with java.lang.Integer, too.

              • 4. Re: Display Integer as currency?
                ginni machamer Newbie

                My object has the attribute as Integer:



                private integer amount;


                with the standard getter and setter.


                Then in the UI, I have the code I originally posted in my JSF.  We are using Seam 2.2.1 with RichFaces 3.3.  The amount fields appear in a table as you see below, but they are not formatted like currency, even though the convertNumber tag is there.  The fields appear in a rich:dataTable.  The column code is like so:



























                rendered="#{record.amountType and (authorizationUpdatable or !authorizationExists)}"







                "The #{record.authorizationForm.formTitle} field must be a number"





                style="width: 98%"




                <f:convertNumber type="currency" integerOnly="true"/>










                reRender="authorizationToolBar, authorizationControlBar"/>










                rendered="#{!record.amountType or (!authorizationUpdatable and authorizationExists)}"




                style="width: 98%"




                <f:convertNumber type="currency"/>



                But the page renders without formatting.