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!

3 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

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>