Friday, June 19, 2009

JSTL formatNumber as percentage gets invalid attribute error

Keywords:
fmt:formatNumber <formatNumber> invalid type attribute: "percentage" percent

Problem:
The JSTL Tag Library documentation seems to indicate that to format a number as a percentage you'd use:

<fmt:formatNumber type="percentage" value="0.5"/>


This gives the error message
<formatNumber>, invalid type attribute: "percentage"

Solution:
Although the documentation for type says "Specifies whether the value is to be formatted as number, currency, or percentage" these aren't the possible values - it's "percent" for percentage:

<fmt:formatNumber type="percent" value="0.5"/>


Notes:
If you know a good reference for JSTL I'd like to know ...

The Appendix A from JSTL in Action is not bad - it documents possible values for formatNumber type at least.

No comments: