Editing 1 entity from 2 screens

Hello! I have 2 entities with a 1 to 1 relationship. For example, a man and a passport. On the man edit screen, I should be able to edit the passport entity. And in the Passport editing screen, the ability to indicate that each belongs to a specific man. Is it possible to implement this and how? The problem is that the passport cannot have a field to save a reference to the entity Man

Can Man have a field to reference to Passport?
Can one Man have many Passport?

We have OneToOne therefore Man have only 1 passport. Edit screen of Man have 2 tabs, the first of edit man, the second of edit passport( there is a field with reference)

Hello,

I made you a small example with an explanation here, hope this helps:

Add person, then passport using Persons menu item. Manage passports using Passports menu item.

Steps:

  1. Create entity Passport
  • @NamePattern(“%s|passportNumber”) or in the visual designer Instance name should be %s|passportNumber (this will be used to display the data in the lookup field)
  1. Create entity Person
  • when done with usual attributes, add last one , name - “passport” Attribute Type - COMPOSITION , Type - “Passport” , Cardinality - One to One
  1. Rightclick Person entity, create view “person-view” - this will be used to create edit and browse form, and in JPA query later.
  2. Create new screen from Passport , Entity browser and editor screens
  3. Create new screen from Person , Entity browser and editor screens, use person-view for both browse and edit screen

So far so good, you can CRUD Person and Passport in Person browse , now to have indicator in Passport edit as to which person it belongs to. (because you can’t have Person attribute added to Passport)

  1. Edit passport-edit.xml to add textfields , enabled is false so they cant be changed
  2. We need to populate this field with desired data, in this case name and surname, to do that we will add loadPersonByPassportNumber method to PassportEdit, and use it onAfterShow event of the screen, that is triggered every time screen is showed. I’m using Optional because if query result is empty, then the result is convenient.

Kind regards,
Mladen

Hello! Thanks, but i must have to edit entity passport in both entities(Person and passport). The problem is in this task.

Hi. If you press the button on the lookup control in the Person Browse - > Person Edit, it will call Passport Edit and you can edit the passport if you created it.