Committing form and backend update

Hello all.
First of all, just comment that this is my first post to the forum. I’ve recently discovered Vaadin and so far, I think it’s a great product, avoiding the need to deal with communications, and providing a great appearance and easy to work with.

And now, my concern:

What I have is a Container (by now a BeanItemContainer on some bean class modelling my data, called Carrier), a Table using this container as DataSource and a tabsheet of forms that are created to edit entries on the table (a new set of forms are added to the TabSheet when a row in the table is clicked).

The component wrapping the forms holds a reference to the Carrier inside the Item clicked on the table, obtained via:

Carrier carrier = ((BeanItem<Carrier>)event.getItem()).getBean();

on the table ItemClickHandler.

What I don’t know how to resolve is the current situation:

-When the commit button on the forms component is clicked, assuming my component has two forms, this is what I do:

...
} else if (source == commitButton) {
  if (form1.isValid() && form2.isValid()) { 
  form1.commit();
  form2.commit();
  app.getCarrierService().updateCarrier(carrier);
  setEditable(false);
...

This is:

  • Check for any validaton error in the forms (yes, I know this will be done anyway in the commit call).
  • Commit the forms (this will update the values on my bean carrier, bound to the forms using a BeanItem(carrier)
  • Then, call my service method updating the values in the database (updateCarrier(carrier)).

Unfortunately, proceeding in this way, if the updateCarrier call fails, there’s no way to rollback values in forms and even worse, in the table bound to the datasource. Hence, the failed-to-update (in the backend) values are now shown in the table, and in the generated form if I manage to click again on its row.

I suppose that the way to proceed could be implementing a more complex Container, directly bound to the database backend actions. However, I’m not able to make clear if some method in my Container will be invoked when forms get commited. Also, I need to receive the modifications in all the forms used to represent the information at once, to make only a backend modification.

So, the questions would be:

  • What is wrong with the pattern I’m using: Table bound to BeanItemContainer, forms created on a BeanItem from the selected Carrier in the table, commit on forms and update on my service using the committed Carrier instance.
  • Is there any painless way to get form values before committing, assuming that my current approach is valid?
  • I think this is a very usual workflow. I’ve read the Vaadin Book, and browsed the sampler, but didn’t find such a case. Is there any source where I could find something like the case I’m working on?

Thank you and best regards.

bump

I’m dealing with the same issue.