I’m attempting to find a solution for an Editor screen button to save the current instance (if requirements met) and open a new blank instance in the same Editor. I found the following link: https://github.com/cuba-labs/demo-64-templates. However, this seems to be outdated. Is there any new instruction of how to accomplish this functionality?
This is great. Thank you. The only remaining issue is any entity instance created with this method does not show up on the browse screen without refreshing the screen, however if one is saved using the regular windowCommitAndClose action, it will automatically show up. Is there an extra step or something available to accommodate this?
From your browser controller add an afterCloseHandler or afterCommitHandler to the edit action. In this handler, reload your table’s container. So whenever the screen is closed/commited it’ll refresh the data automatically.
Are you looking for a new entity with the same field values, or the same entity loaded without clearing? The difference is a new entity will create a new Id, so upon saving, you will have two records with different IDs but the same field values.
If you’re looking for a new entity with the same field values as the saved entity, something like this would work:
@Inject
private DataContext dataContext;
@Inject
private Notifications notifications;
@Subscribe("saveAndNewBtn")
public void onSaveAndNewBtnClick(Button.ClickEvent event) {
commitChanges().then(() -> {
notifications.create()
.withDescription("Entity saved")
.withType(Notifications.NotificationType.HUMANIZED)
.show();
// Save existing values to use on next entity
Test test = getEditedEntity();
// Remove previous entity from data context
dataContext.clear();
// Create the new entity for the existing screen
Test newEntity = dataContext.create(Test.class);
// Copy values saved from previous entity
newEntity.setName(test.getName());
newEntity.setTitle(test.getTitle());
newEntity.setFoo(test.getFoo());
// Set the new entity in the edited entity container
getEditedEntityContainer().setItem(newEntity);
});
}
Note that in this example, Test is just what I named this entity for this example.
Adam