tags:

views:

1391

answers:

3

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?

A: 

You could setup a converter with that pattern, but that sounds like the exact opposite to what you want.

sblundy
+2  A: 

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.

William
sad but true. i am havong the same problem right now.
Andreas Petersson
again. i just noticed i had already answered to this exact same question months ago. SO is becoming my personal notepad.
Andreas Petersson
+1  A: 

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.

Andreas Petersson
That is actually completely in the JSF spirt. I'm trying to write as little code dependent on JSF as possible. Mostly just a lofty design goals but I think it makes our project clearner, more maintainable etc.
William