5 Replies Latest reply on Sep 3, 2007 9:14 AM by Adrian Mitev

    BigDecimal and JSF <f:convertNumber>

    steve tynor Novice

      Seam 1.2.1-GA, JSF 1.2, JBoss 4.2.1-GA

      I have some properties of type BigDecimal that I need to display with commas (e.g. 300,000.00). I can't use f:convertNumber's pattern:

      <h:inputText id="#{id}" size="10" value="#{value}" required="#{required}">
       <f:convertNumber pattern="#,##0.00" />

      since this results in a runtime error -- f:convertNumber creates a java.lang.Number -- which, sadly, BigDecimal does not conform to.

      /WEB-INF/facelets/tags/inputCurrency.xhtml @15,76
      value="#{value}": /capital/CapitalCallEdit.xhtml @37,81
      java.lang.IllegalArgumentException: argument type mismatch

      It's trying to pass a Long to the setCallAmount(BigDecimal val) setter:

      NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
      NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
      DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
      Method.invoke(Object, Object...) line: 585
      BeanELResolver.setValue(ELContext, Object, Object, Object) line: 108
      FacesCompositeELResolver(CompositeELResolver).setValue(ELContext, Object, Object, Object) line: 68
      FacesCompositeELResolver.setValue(ELContext, Object, Object, Object) line: 93
      AstValue.setValue(EvaluationContext, Object) line: 114
      ValueExpressionImpl.setValue(ELContext, Object) line: 249
      TagValueExpression.setValue(ELContext, Object) line: 93
      AstIdentifier.setValue(EvaluationContext, Object) line: 66
      ValueExpressionImpl.setValue(ELContext, Object) line: 249
      TagValueExpression.setValue(ELContext, Object) line: 93
      HtmlInputText(UIInput).updateModel(FacesContext) line: 765
      HtmlInputText(UIInput).processUpdates(FacesContext) line: 697
      UIValidateAll(UIComponentBase).processUpdates(FacesContext) line: 1056
      UIDecorate(UIComponentBase).processUpdates(FacesContext) line: 1056
      HtmlPanel(UIComponentBase).processUpdates(FacesContext) line: 1056

      Is this a bug? I'm not certain - the Core JSF book (Geary/Horstman) suggests that f:convertNumber should work with BigDecimal in JSF 1.2, but I can't find any specific example that explicitly shows it should work.

      I can't find a way to use NumberFormat-style conversions with BigDecimal with any off the shelf converters.

      This seems to be something that many others would have encountered before me -- can anyone point me to a way to convert BigDecimal with a pattern format?