There are 4 entities:
Person - contains personal info about an individual
Address - contains postal addresses of an individual and relates to Person as many2many
Phone - telephone numbers, linked to Person as many2many
Customer - contains attributes of a customer and again relates to Person as many2many
Objective:
Editor to be developed to meet following requirements. Editor should be able to create all described entities by entering all mandatory info to a single form. Also CustomerID sequence to be generated automatically. I.e. we want to have single form to add info about a customer instead of 4 different editors and switching between those.
To do it:
- I created joined datasources (presonDS - main editor datasource)
<dsContext>...
<datasource id="personDs" class="com.company.myapp.entity.Person">
<collectionDatasource id="addressesDs" property="addresses"/>
<collectionDatasource id="phonesDs" property="phones"/>
<collectionDatasource id="customerDs" property="customer"/>
</datasource>
</dsContext>
- Initialized following entities from the editor’s controller:
public class CustomerEdit extends AbstractEditor<Customer> {
@Inject
private UniqueNumbersService customerSeq;
private HashSet<Phone> phoneSet = new HashSet<Phone>();
private HashSet<Address> addressSet = new HashSet<Address>();
private HashSet<Customer> customerSet = new HashSet<Customer>();
@Override
public void init(Map<String, Object> params) {}
protected void initNewItem(Person item) {
Long customerID = customerSeq.getNextNumber("customerSeq"); Customer customer = new Customer();
customer.setCustomerID(customerID); customerSet.add(customer); item.setCustomer(customerSet);
Address address = new Address(); addressSet.add(address); item.setAddresses(addressSet);
Phone phone = new Phone(); phoneSet.add(phone); item.setPhones(phoneSet);
}
}
Finally I get all fields of all linked entities which do not work, except of Person. Any input to Person disappears when field gets unfocused. Obviously I cannot submit changes, because all the mandatory fields are empty.
How can I make it work? And what’s wrong with my approach?