3 Replies Latest reply on Jan 30, 2014 12:01 PM by Christian Sadilek

    Standart Errai bind doesn't support empty values for numeric types

    Olexandr Demura Newbie

      Errai DataBinder doesn't translate empty textbox values into null values in binded model.
      For example, suppose there are bindable class and autobound template



      public class ValueHolder {

        private String comment; //get+set

        private BigDecimal amount; //get+set




      public class ValueEditor {



        private DataBinder<T> binder;



        private TextArea comment = new TextArea();



        private TextBox amount = new TextBox();



      It works perfectly fine with numeric values, but cleaning input would not clean model value,
      and change in comment input would cause amount to restore previously entered value.

      It's caused by NumberFormatException in BigDecimal constructor called from

      org.jboss.errai.databinding.client.api.Convert.to(BigDecimal.class, "")


      Is it designed to reject empty numeric inputs?

      If not, following patch to Convert allows to clean numeric inputs.


      public class Convert {

      + private static final HashSet<Class<?>> SUPPORTED_CLASSES = new HashSet<Class<?>>(Arrays.asList(

      + Integer.class, Long.class, Float.class, Double.class, Boolean.class, Date.class, BigDecimal.class, BigInteger.class));

      private static final Map<ConverterRegistrationKey, Converter> defaultConverters =

        new HashMap<ConverterRegistrationKey, Converter>();


        return o.toString();


        else if (o.getClass().equals(String.class)) {

      + String string = (String) o;

      + if (string.length() == 0 && SUPPORTED_CLASSES.contains(toType)) {

      + return null;

      + }

        if (toType.equals(Integer.class)) {