I would suggest creating separate edit screens for Employee and Student. Below is an example of possible implementation.
Person.java
@JmixEntity
@Table(name = "PERSON")
@Entity
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
@Inheritance(strategy = InheritanceType.JOINED)
public class Person {
@JmixGeneratedValue
@Column(name = "ID", nullable = false)
@Id
private UUID id;
@Column(name = "VERSION", nullable = false)
@Version
private Integer version;
@InstanceName
@Column(name = "FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
Employee.java
@JmixEntity
@Table(name = "EMPLOYEE")
@Entity
@PrimaryKeyJoinColumn(name = "ID")
public class Employee extends Person {
@Column(name = "EMPLOYEE_INFO")
private String employeeInfo;
Student.java
@JmixEntity
@Table(name = "STUDENT")
@Entity
@PrimaryKeyJoinColumn(name = "ID")
public class Student extends Person {
@Column(name = "STUDENT_INFO")
private String studentInfo;
In UI, create a browse screen for Person entity and separate editors for Employee and Student.
In the Person browse, configure separate actions and buttons for creating Employee and Student:
<groupTable id="personsTable"
width="100%"
dataContainer="personsDc">
<actions>
<action id="createEmployee" type="create" caption="Create employee">
<properties>
<property name="screenId" value="Employee.edit"/>
</properties>
</action>
<action id="createStudent" type="create" caption="Create student">
<properties>
<property name="screenId" value="Student.edit"/>
</properties>
</action>
<action id="edit" type="edit"/>
<action id="remove" type="remove"/>
</actions>
<columns>
<column id="firstName"/>
<column id="lastName"/>
</columns>
<simplePagination/>
<buttonsPanel id="buttonsPanel"
alwaysVisible="true">
<button id="createEmployeeBtn" action="personsTable.createEmployee"/>
<button id="createStudentBtn" action="personsTable.createStudent"/>
<button id="editBtn" action="personsTable.edit"/>
<button id="removeBtn" action="personsTable.remove"/>
</buttonsPanel>
</groupTable>
The actions should create corresponding types, it’s done in controller:
@UiController("Person.browse")
@UiDescriptor("person-browse.xml")
@LookupComponent("personsTable")
public class PersonBrowse extends StandardLookup<Person> {
@Autowired
private Metadata metadata;
@Install(to = "personsTable.createEmployee", subject = "newEntitySupplier")
private Person personsTableCreateEmployeeNewEntitySupplier() {
return metadata.create(Employee.class);
}
@Install(to = "personsTable.createStudent", subject = "newEntitySupplier")
private Person personsTableCreateStudentNewEntitySupplier() {
return metadata.create(Student.class);
}
}
The edit action opens the corresponding editor depending on the selected entity type.
The demo project is attached:
demo.zip (95.3 KB)