Textfield Doublle Range Validator Issue

I have created a simple form using vaadin designer, have created a textfield by applying double range validator but the validation is not working.Accepting values beyond defined range.

Here is my sample code.

angleofrotation.addValidator(new DoubleRangeValidator(“value have to be in between 0.0 to 359.9”,0.0,359.9))

Hey Aneja,

I think you need to convert the string input to double.

Just an example:

TextField tf = new TextField();
tf.setConverter(new Converter<String, Double>() {

  @Override
  public Double convertToModel(String value,
      Class<? extends Double> targetType, Locale locale)
      throws com.vaadin.data.util.converter.Converter.ConversionException {
    if (value == null)
      return null;
    if (value.isEmpty()) {
      // Or set some kind of default value at start.
      return 0.0;
    }
    return Double.parseDouble(value);
  }

  @Override
  public String convertToPresentation(Double value,
      Class<? extends String> targetType, Locale locale)
      throws com.vaadin.data.util.converter.Converter.ConversionException {
    if (value == null)
      return null;
    return String.valueOf(value);
  }

  @Override
  public Class<Double> getModelType() {
    return Double.class;
  }

  @Override
  public Class<String> getPresentationType() {
    return String.class;
  }

});
tf.addValidator(new DoubleRangeValidator(
    "value have to be in between 0.0 to 359.9", 0.0, 359.9));
tf.setImmediate(true);

It is working now,was missing this only.

Thanks Joacim

It is not very obvious that you need to make a custom converter for Range to work. This should be all in one functionality.
Your write less code if you just make your custom validator.