Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Table field validation
I am currently testing Vaading and am struggling with the table component and validation.
I have a table which is populated via hibernate, and is editable. The changes are committed when the user clicks on a simple save button (commit() is called on the table, and I iterate through each modified row to saveorupdate). I have also overriden the defaultfactory to add a regexpvalidator on a property.
The validator works when the user has the mouse over the field, and the invalid changes are not committed to the datasource so it works fine. Though, the problem is that I have no trace that the changes weren't committed. No exceptions are thrown and I can't warn the user there was a problem with some fields.
Shouldnt the commit() operation on the table throw an invalidvaluexception I could catch?
I have recenlty done the same thing with a table. I had to get isModifiied and isValid to work. Unfortunately the table isn't a real component container, and thus isModified and isValid didn't work in the way that I anticipated from them. What you have to do is override those functions and implement them yourself. You have to gather a reference of all the fields that the fieldFactory creates into a collection and run either isValid or isModified against them directly.
This ticket has a wider description about this problem and an example of how it can be done: http://dev.vaadin.com/ticket/3796#comment:3
That worked nice and well with isModified, but even a bigger problem is that the table components has a bug that was a total showstopper for me when I tried to implement isValid. The bug is that a table with a fieldFactory creates the double amount of fields compared to what it needs. Half the fields normally just disappears to oblivion and only the right fields are shown in the table. Problems arises however when you collect references to these fields. You will always get the result that the table is not valid if you for example put setRequired(true) on the fields. Half the fields will always return isValid = false as they are always empty when you can't possibly fill a value to them.
I reported the bug to the Vaadin team at it was fixed within minutes. The fix will however not appear before the version 6.3 so you have to either wait for that or use a nightly build. The ticket about the bug: http://dev.vaadin.com/ticket/4299
Thanks for the clear answer. Overriding those functions shouldnt be too much trouble.
How can I get the content of the edited fields after that I set the table isEditable(true);
I tried to read so many examples but none of them take the edited data.
could someone plz help me because I tried alot !!! thank u !!!