4

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?

William
  • 6,338
  • 4
  • 32
  • 36

3 Answers3

4

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
  • 6,338
  • 4
  • 32
  • 36
2

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
  • 16,248
  • 11
  • 59
  • 91
  • 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 Sep 18 '08 at 00:23
0

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

sblundy
  • 60,628
  • 22
  • 121
  • 123