Bug with getValue() of a TextField object in a Form

Hi,

First of all, I like to say that you guys have done a magnificent job with Vaadin.

I have encounter a problem with the getValue() method of the TextField object. What happens is when I have a value in it “Test” and I delete everything in the TextField, I expect that it will return me an empty string “”. But it doesn’t. getValue() returns me the value “Test” even though the value is “”.

What is also not working is that I have setRequired to true. When I delete everything from “Test” to “”, since the getValue() returns “Test”, it does not trigger a validation error as it should.

Would someone have an idea how to fix this?

Thank you,
Paul

Is your TextField.setImmediate(true) set? If so, then changes made to the textfield are sent to the server when the field is changed, otherwise it won’t be sent until a button is pressed (or other action) so that data is transmitted from the browser to the server.

Look at Form.setWriteThrough() as it relates to Form.commit()/Form.discard().

Not sure how Form.setImmediate() compares to TextField.setImmediate() work exactly, but it seems if you have validators on any of your Fields, you need the former, and if you just want a single field’s value to be sent when it’s changed, you can put it on the TextField.

Hope this helps…

I have tried all possible combinations on the TextField and on the Form, I am still getting the previous value on getValue() when I put an empty String.

Did anybody encounter the same problem?

I have the same problem. Is there a place where I can change the value by myself? Because right now if i set the empty field in the textField I get the previous value as it was written. I want to set a value by myself.

Are you using a recent version of Vaadin? TextFields should definitely allow empty strings, and definitely do in most applications.

Required is does not trigger quite the same kind of validation error - it is not a validator.

Make sure the TextField is immediate (either directly or via a containing Form being immediate), check that invalidAllowed is true (default value), remove your validators one by one to see if any of them is causing problems and check what you have set as nullRepresentation on the field and that nullSettingAllowed is true if mapping an empty string to null.

Thank you, Henri. It works :wink: