How to create multiple data in a screen?

Hi,

I want to create multiple rows of records from a screen.

Example: user key in a range from 1 to 100. After user click ok button, system will generate 1 to 100 records into database.

My problem is, can i use AbstractEditor for this operation and override the commitAndClose function to write the data? But somehow i am stuck to refresh the table.

@Override
public void commitAndClose() {
    if (locationService.createLocation(locationDs.getItem())) {
        locationDs.commit();
    }
}

Can someone help to give me some idea?

Thanks in advance.

Hi,

Could you clarify whether you want these generated entities to be associated with the editing one, or are you trying to facilitate entities creation by using the editor screen?

Regards,
Gleb

Hi,

I would like to facilitate entities creation by using the editor screen.

Thanks,

Regards,
Adrian

If the generated entities have nothing to do with the entity corresponded to the editor, then I see no reason to override and alter commitAndClose(). I suggest the following code:

@Inject
private DataManager dataManager;
@Inject
private Metadata metadata;

public void generate() {
    int count = 10;

    // DTO that contains information about currently committed entities.
    CommitContext commitContext = new CommitContext();
    for (int i = 0; i < count; i++) {
        // Create a new instance and set the attribute values
        Customer customer = metadata.create(Customer.class);
        customer.setName("Name" + 1);
        customer.setEmail("example@mail.com");
        // Every created instance is added to the commit context
        commitContext.addInstanceToCommit(customer);
    }
    // Finally, commit all newly created entities
    dataManager.commit(commitContext);
}

You can use this code snippet in the place you prefer, for instance in a browser screen, service method etc., so there is no need to alter the default behavior of committing an editing entity.

1 Like

Hi,

Thank you for your advise.

I trying the solutions, but hit other issue. will update here again.

Thanks.