IntegerRangeValidator not working

I’ve noticed the following problem in Vaadin 7.2.4,
I have a textfield that uses the IntegerRangeValidator
testTextField.addValidator(new IntegerRangeValidator(“Not Valid”,0,120);

Whenever an integer is input in the field I always get error…
Any ideas?

Is the problem specifically in 7.2.4 or does it occur with earlier versions as well?

I don’t see any problem with IntegerRangeValidator, at least in
this example
. It uses just explicit validation though, not automatic validation, but that shouldn’t make a difference.

The problem is that the standard ObjectProperty of Textfield is of type String. So whenever you enter something it looks if a String is inside that range which is always false.
Your code looks something more like this(code taken from the
Validation Example

// Have a property of integer type
ObjectProperty<Integer> property = new ObjectProperty<Integer>(0);
// Bind it to a field
final TextField field = new TextField("Age", property);
// Define validation
field.addValidator(new IntegerRangeValidator( "The value must be integer between 0-120 (was {0})", 0, 120));
// Run validation
Button validate = new Button("Validate");
validate.addClickListener(new ClickListener() {
private static final long serialVersionUID = 7729516791241492195L;
@Override public void buttonClick(ClickEvent event) {
try {
} catch (InvalidValueException e) {;
} } });

(Sry for the formating but it screwed up a bit when copying)

dealin’ with the same problem. Seems that NumberField Vaadin add-on could be the solution but I would like to stay simple as much as possile. Any ideas?

I have used the solution that Marius Reinwald gave: adding an Integer property to the field. The problem is that I also have a StringLenghtValidator to that field, and now it doesn’t pass that validator, I imagine that’s because it is not a string but an integer.
Any ideas of how to solve this?

As I suspected, Validator are useless, too much code for a simple NumericField, ObjectProperty’s constructor doesn’t allow null, so the field has to initiate with an useless default value.

PD: I assume u can’t have both, you can define a lenght limitation using ranges right?, or u could define a RegEx Validator

That’s true, I’ll try that, thanks!


I’m sorry to bother you with my issue here, but I do not see a way to put the question on the forum. I can only reply to existing questions. There is no “Create new thread” (or similar) option. Anyone can help?

You need to go to the main forum page and select a category, for example:!/category/1007558

I see, thanks, but when I choose ‘Framework Data Binding’ from your link, there is no ‘New post’ buton…
Anyway, this satisfies me…