Question
Trying to keep all the presentation stuff in the xhtml on this project and I need to format some values in a selectItem tag have a BigDecimal value and need to make it look like currency. Is there anyway to apply a <f:convertNumber pattern="$#,##0.00"/>
Inside a <f:selectItem>
tag?
Any way to do this or a work around that doesn't involve pushing this into the java code?
Solution
After doing some more research here I'm pretty convinced this isn't possible with the current implementation of JSF. There just isn't an opportunity to transform the value.
http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/f/selectItem.html
The tld shows the itemLabel
property as being a ValueExpression
and the body content of <f:selectItem>
as being empty. So nothing is allowed to exist inside one of these tags, and the label has to point to a verbatim value in the Java model. So it has be be formatted coming out of the Java model.
OTHER TIPS
being a beginner to jsf i had a similar problem, maybe my solution is helpful, maybe its not in the "jsf spirit"
i just created a custom taglib and extended the class (in my case org.apache.myfaces.component.html.ext.HtmlCommandButton) and overrided the setters to apply custom parameters.
so instead of <t:commandButton/>
i used <mytags:commandButton/>
, which is as flexible as i want.
You could setup a converter with that pattern, but that sounds like the exact opposite to what you want.