1

According to the TLD, convertNumber accepts ValueExpressions for its pattern attribute. But it doesn't seem to work (JSF 1.2 RI):

<h:outputText value="#{Test.numberValue}">
    <f:convertNumber pattern="#{Test.numberPattern}" />
</h:outputText>

outputs

0.0210000000000000013045120539345589349977

(Test.numberValue evaluates to 0.021, Test.numberPattern to "0.00%") If I use a String literal, everything works fine:

<h:outputText value="#{Test.numberValue}">
    <f:convertNumber pattern="0.00%" />
</h:outputText>

outputs

2,10%

The h:outputText is part of a h:dataTable column, if that matters.

Zeemee
  • 10,486
  • 14
  • 51
  • 81

1 Answers1

2

The h:outputText is part of a h:dataTable column, if that matters.

Found out that it actually matters, please see this question about convertDateTime in a datatable. According to that (thanks to BalusC, as always), this is my solution:

Custom converter:

public class DynamicNumberConverter extends NumberConverter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        setPattern((String) component.getAttributes().get("pattern"));
        return super.getAsObject(context, component, value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        setPattern((String) component.getAttributes().get("pattern"));
        return super.getAsString(context, component, value);
    }
}

Markup:

<h:outputText value="#{Test.numberValue}">
    <f:converter converterId="DynamicNumberConverter" />
    <f:attribute name="pattern" value="#{Test.numberPattern}"/>
</h:outputText>
Community
  • 1
  • 1
Zeemee
  • 10,486
  • 14
  • 51
  • 81