2 Replies Latest reply on Jan 11, 2011 4:28 PM by aareshchanka

    Custom Converter that extends NumberConverter

    tomas06
      Hi all,

      I wrote this converter :

      @Name("lmNumberConverter")
      @Converter
      public class LMNumberConverter extends javax.faces.convert.NumberConverter{    
             
              @Override
              public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
                      BigDecimal curVal = new BigDecimal(value.toString());
                      if (curVal.compareTo(BigDecimal.ZERO) != 0){
                      return super.getAsString(context,component,value);
                        }
                        else
                                return "";
                }

             
      }

      So far nothing special, it's just to modify the behavior of the NumberConverter in order to display an empty string in case of a 0 value.

      I call it that way :
      <f:converter converterId="lmNumberCurrencyConverter" type="currency" currencySymbol="$" maxFractionDigits="2" />

      The converter is well called, and in case of a 0 value I well have an empty string, which is good.

      My problem is that the converter does not take the properties :  type, currencySymbol and maxFractionDigit that it should inherite from the NumberConverter,
      Could anyone explain me why?

      Thanks