I use MultiSelectComboBox on multiple pages, but only one page has this problem. The createTableEditorMultiSelect method for this page is different from the other pages. On this page, the two fields are stored in separate tables, not in the same table as the parent entity.
@OneToMany(
cascade = CascadeType.ALL,
mappedBy = "parent",
fetch = FetchType.EAGER,
orphanRemoval = true
)
@Fetch(FetchMode.SUBSELECT)
private Set<ToolClassA> toolClassesA = new HashSet<>();
@Transient
private Set<ToolClassA> backupToolClassesA = new HashSet<>();
// used to temporarily hold values when another field changes
@OneToMany(
cascade = CascadeType.ALL,
mappedBy = "parent",
fetch = FetchType.EAGER,
orphanRemoval = true
)
@Fetch(FetchMode.SUBSELECT)
private Set<ToolClassB> toolClassesB = new HashSet<>();
Here’s my method for creating a multi select:
select.addSelectionListener(e -> {
boolean refreshRow = false;
if (currentItem != null && gridEditor != null
&& gridEditor.getItem() != null
&& gridEditor.getItem().equals(currentItem)) {
Set<String> selected = e.getValue();
// If user selects "ALL", clear other selections and set special value in the entity
if (selected.contains("ALL")) {
if ("columnA".equalsIgnoreCase(column.getKey())) {
Set<ToolClassA> values = new HashSet<>();
values.add(convert("ALL")); // placeholder for special "ALL" value
currentItem.setToolClassesA(values);
refreshRow = true;
}
if ("columnB".equalsIgnoreCase(column.getKey())) {
Set<ToolClassB> values = new HashSet<>();
values.add(convert("ALL"));
currentItem.setToolClassesB(values);
refreshRow = true;
}
}
// mark field and row as edited
markFieldEdited(currentItem, column.getKey(), e.getOldValue(), e.getValue());
markRowEdited(currentItem);
updateEditorStyle(currentItem, column);
if (refreshRow) {
binder.readBean(currentItem);
}
persistEditorValues();
}
});
I added a breakpoint to see which line causes the overlay to close, but the overlay does not close until the method finishes running
Here’s how I define the editor for this column:
// Create the MultiSelectComboBox for this column
toolMultiSelect = createTableEditorMultiSelect(column, toolOptions, null);
binder.forField(toolMultiSelect)
.withConverter(toolConverter) // generic tool converter
.withValidator(selectedTools -> ValidationUtils.validateNotNull(selectedTools, canSkipValidation()),
"Required") // generic validation
.bind("toolCollection"); // the name of the entity property (a Set/Collection)
// Set the editor component for the column
column.setEditorComponent(toolMultiSelect);
How can I debug this further to pinpoint why the overlay closes?