Reputation:
I bound several text fields to an entity in the IDE Rapidclipse that uses Vaadin 14 and JPA/Hibernate. The aim is to write the input data on button click into the referring database that is defined as datasource.
I already found this documentation
Writing manually.
So my understanding of this is like that: At first i need to create a new bean of the entity (Test test = new Test()
). Then all input data should be assigned to the attributes of the bean(binder.writeBean(test)
). That's as far as the documentation goes. But how does the data get inserted into the table of the entity in my database? Do i need the TestDAO class?
In Vaadin 7, which was used in the former Rapidclipse version, it worked like this:
fieldGroup.setItemDatasource(new Test());
...
fieldgroup.save()
Upvotes: 0
Views: 482
Reputation: 2652
Binder
is used to bind attributes of a Bean
to a form(TextFields, for example) displayed in UI. So when you are doing something like this How to Bind Form Data
Binder<Person> binder = new Binder<>(Person.class);
TextField titleField = new TextField();
// Start by defining the Field instance to use
binder.forField(titleField)
// Finalize by doing the actual binding
// to the Person class
.bind(
// Callback that loads the title
// from a person instance
Person::getTitle,
// Callback that saves the title
// in a person instance
Person::setTitle);
you are exactly stating that titleField
displays a title of a person. Binder
is not related to/responsible of a DB persistence.
In the documentation you linked, in all examples there is a row similar to this:
MyBackend.updatePersonInDatabase(person);
. It's a responsibility of a developer to persist object into underlying database. Flow is a UI framework and that is the reason you are free to choose a database provider/technology.
Regarding Vaadin 7, where you have found an example? I can't find a method save
on a FieldGroup
class FieldGroup API
Maybe someone has extended it and added a needed functionality?
So, for example, if you are using hibernate something along the line of this:
session.save(emp);
will insert your object into DB.
Taken from here: Hibernate Insert Query Tutorial
Some other useful links:
Upvotes: 2