Formatting Currency with Java Server Faces

This is simple but VERY neat.

ok

1. Create a textbox, bind it to a numeric field
2. Create a NUMBERCONVERTER by selecting it for the field

Converter:numberConverter1

3. In your Java init code for your server faces web page…

numberConverter1.setMaxFractionDigits(2);
numberConverter1.setMinFractionDigits(2);
numberConverter1.setPattern("£#.00");

(UK)

        numberConverter1.setMaxFractionDigits(2);
        numberConverter1.setMinFractionDigits(2);
        numberConverter1.setPattern("$#.00");

(USA)

Then any boxes you assign that number converter are auto formatted as currency!

Advertisements

About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on July 4, 2008, in Uncategorized and tagged . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: