Using initNewItem Method

Initial values can also be defined in the initNewItem() method of the screen controller of the created entity.

Consider the following entities:

composition recipe 3

In the demo application, CustomerDetails attribute (info) is edited on the same screen as Customer itself. It requires creating of a CustomerDetails instance together with the owning Customer.

  • customer-edit.xml - a customer edit screen descriptor. It contains a nested datasource for a linked CustomerDetails instance. The infoField text area component is connected to this datasource.

  • CustomerEdit.java - the screen controller. It defines the initNewItem() method that creates a new CustomerDetails instance and sets it to a new Customer. The created instance will be available through the nested datasource and later saved to the database when the screen is committed.