Search code examples
gwtsmartgwtsmartgwt-pro

How to set a max value for IntegerItem


I want to set a max value for an IntegerItem. If a user enters a large number, I want to return a validation error.

final IntegerItem qte = new IntegerItem("qte", "Qte");

If a user enters, for example, a number below 5, this is OK, but a large number should return a validation error.


Solution

  • SmartGWT has validators pre-defined that you can use. The list of validators is listed here. In this case, you would benefit from the IntegerRangeValidator.

    IntegerRangeValidator integerRangeValidator = new IntegerRangeValidator();
    integerRangeValidator.setMin(1);
    integerRangeValidator.setMax(9999); // for example
    populationField.setValidators(integerRangeValidator);