trim form fields before binder.writeBean()

Is there an elegant way to trim all strings entered in a form before using binder.writeBean()?

Yes, I can do that by setting the new object in advance with every trimmed String property, as the form isn’t that big, but in general, how are others doing this?

I don’t exactly understand your use case. I usually do this in a change listener.

will write little later about, too hungry now, me and the dog, too :wink:

Soo,
in my case it’s a simple form, but others may have bigger forms. If e.g. it is about persons, some people tend to do Copy&Paste addresses etc. from other applications. That may cause additional spaces.

As long as we just display the data here + there, all is fine. But sometimes we need to exchange them via REST and Json. And on the receiver side it might cause troubles if there are e.g trailing spaces.

Therefore I would like to assure, that the data from a form get trimmed into the DB, that will avoid to use trim here and there and elsewhere. I had the (little) hope that binder might have kind of that implemented but seems not. Found a similar question within the old vaadin forum (3y old)

https://vaadin.com/forum/thread/17865614/binder-and-auto-trim

Ok now I understand :slightly_smiling_face: We’ve created subclasses of TextField and TextArea to do such things and add a BlurListener

So we don’t do this with the Binder but with the Component

Aah yes, sounds pretty cool :slightly_smiling_face:
I will have this in mind. Right now there are only 4 fields at all in our form which would need a trim, but I am sure the next (bigger) form is not too far away :wink:

I’ve created a subclass of binder and automatically add a trim converter on string fields :sweat_smile: