When I create a student, I shall also “create” the reference to the teacher.
Means,
when I open the editor screen of the student, I shall have also the “attributes” of the teacher, that I have to fill inside the editor screen.
For example:
Student-Editor:
student name:
age:
Teacher name: //this is a attribute from Teacher Entity
Teacher subjects: //this is a attribute from Teacher Entity
Is it possible to display the informations like this?
Means, by creating an student, it will automatically create also the teacher…
Yes, it’s possible. First of all, you need to define a nested datasource for the teacher property and then setup FieldGroup’s fields to refer to a teacher attributes:
In the screen controller override the initNewItem method as follows:
public class StudentEdit extends AbstractEditor<Student> {
@Inject
private Metadata metadata;
@Override
protected void initNewItem(Student item) {
// Create a new teacher every time we create a student
Teacher teacher = metadata.create(Teacher.class);
item.setTeacher(teacher);
}
}
No need to use, it’s needed for tracking changes in a teacher entity in order to commit it and show notification before the editor is closed in case of unsaved changes.
If something doesn’t work, please be more specific about the proper case to reproduce.