Come on guys, please help me on this one. This is the 3rd time I post something related to this. Please help a poor new Vaadin adopter.
When working with forms, every time an event happens the event handler is called more than once. Example:
form.getFooter().addComponent(
new Button(Messages.getMessage("save"), new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
try {
form.commit();
Provider provider = (Provider) ((BeanItem) form
.getItemDataSource()).getBean();
provider.setName(provider.getName().trim());
ManagerFactory.getInstance().getProviderManager().createOrUpdateProvider(provider);
showSuccessMessage();
close();
} catch (InvalidValueException e) {
// Vamos deixar o formulário cuidar dos erros
}
}
}));
This code is causing more than one insert for each time the save button is clicked. If I do it without Forms everything runs fine. Am I the first noticing this? Is there a problem in my code?
Apologies on that you haven’t gotten an answer earlier. I started looking at your problem, and was about to test run it, but it is kinda hard to do that when the example isn’t a whole test case application to be tested, and the code has dependencies to seemingly other libraries. For example, I don’t know what the Provider and ManagerFactory is.
Could you do a new test case so that it would be easier to test? Create a new Vaadin application with no other libraries than the Vaadin jar, do a minimal application that shows that the handler gets called twice. It is so much easier to test and help you if I could just copy paste your whole application’s code (30-50 rows of code or something) to eclipse and hit run to see the problem.
Thank you for the Help. While trying to build a test Application so that you could take a look I found out my mistake. The problem was on my code, sorry
What was the problem with your code?? I have the same problem, the form.commit is firing a ValueChangeEvent. I only want the ValueChangeEvent to happen when the combo box value is changed in the UI.
Do you do something else when you do the form.commit()? for example, do you clear the fields from their values after the user clicks save? Doing a textfield.setValue(“”); fires a ValueChangeEvent too.