Jun 06

Quick Tip: Formatting Number Columns with DisplayTag

Tag: displaytag,java,jsp,spring,webpmularien @ 9:39 pm

Displaytag supports easy display of formatted number columns using the format attribute on <display:column> – however, it’s not really well documented on the Displaytag site. Here’s how to do simple number formatting without requiring a decorator class:

<displaytag:column property="amount" title="$ Amount" format="{0,number,#.##}"/>

This will display a decimal formatted to a maximum of 2 decimal places!

4 Responses to “Quick Tip: Formatting Number Columns with DisplayTag”

  1. Vk says:

    Do you know where can I find all the formatting rules?

    Thanks

  2. pmularien says:

    Well, this syntax is actually instantiating a MessageFormatColumnDecorator behind the scenes. That Decorator simply hands off the contents of the column to an instance of MessageFormat with the specified pattern. So, the answer to your question is – “look at the MessageFormat Javadoc”. Hope that helps!

  3. Vk says:

    It helped indeed!!

    Thank you

  4. Tamer says:

    Hi, when I sort a displaytag column that contains numbers it is treated as string for example: (1,10,11,2,3,…etc)
    I want the column to be sorted as integers like this (1,2,3,4,…,10,11,..etc)
    How do I acheive this ?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">