Hello again. I wonder if I could get a little help with a process I’m trying to right.
I have a record that I want to commit when the user presses a button; after committing it, a process then creates another record and attaches it to via an association. Then I want to pick up the record from the database and put it back on the screen.
Here’s how I tried to do it:
private void kickOffProcess() {
// First of all, we commit any changes that have been made.
// They may have changed the record and not saved before hitting
// the start process button.
manuscriptDs.commit();
Manuscript manuscript = manuscriptDs.getItem();
ProcessTemplate processTemplate = manuscript.getProcessTemplate();
//Attach the new record to the manuscript
processService.copyProcessTemplateToManuscript(processTemplate, manuscript);
// Now refresh the data source from the database to pick up the changes.
Manuscript refreshedManuscript = manuscriptService.getManuscriptById(manuscript.getId());
// At this point the refreshed record is correct
ManuscriptProcess manuscriptProcess = refreshedManuscript.getManuscriptProcess();
// Now get the first stage
Optional<ManuscriptStage> initialStage = manuscriptProcess.getManuscriptStages().stream()
.filter(manuscriptStage -> manuscriptStage.getSequenceOrder() == 1)
.findFirst();
if (initialStage.isPresent()) {
refreshedManuscript.setCurrentManuscriptStage(initialStage.get());
manuscriptDs.setItem(refreshedManuscript); // <-- This is not right
}
}
When I try to set the manuscriptDs data source to the new manuscript, the fields I set before committing the record seem to have been reset back to null. My guess is that the setItem function doesn’t do what I think it does, and that there is a proper way to refresh the record on the screen.
EDIT:
Okay, I’ve been playing around with it a little bit more, and the problem is that I don’t understand what happens when I commit a data source. Looking at the debugger output:
Execute manuscriptDs.getItem() --> The fields on the screen are set correctly
Execute manuscriptDs.commit()
Execute manuscriptDs.getItem() --> Now the fields are blank. Why? They have been written to the database, but they have been erased from the data source.