4. Set Up Interaction Between Views
The user ought to have the capability to modify and save the base location by clicking on the map marker. As of now, our application doesn’t offer this functionality.
Go to the LocationLookupView
view controller and produce setter ang getter methods to pass the location we intend to display or save.
public Location getSelected() {
return selected;
}
public void setSelected(@Nullable Location selected) {
this.selected = selected;
currentLocationField.setValue(selected);
if (selected != null) {
setMapCenter(selected.getBuilding());
}
}
Navigate to the UserDetailView
view controller and locate the onLocationFieldSelect()
handler. Our goal is not only to open a dialog, but also to pass the previously saved location for the edited user. Additionally, we need to retrieve a result from the dialog once it has been closed. Let’s proceed with the necessary modifications to the handler:
@ViewComponent
private JmixValuePicker<Location> locationField;
@Subscribe("locationField.select")
public void onLocationFieldSelect(final ActionPerformedEvent event) {
dialogWindows.view(this, LocationLookupView.class)
.withAfterCloseListener(closeEvent -> {
if (closeEvent.closedWith(StandardOutcome.SELECT)) {
locationField.setValue(closeEvent.getView().getSelected()); (1)
}
})
.open()
.getView()
.setSelected(getEditedEntity().getLocation()); (2)
}
1 | The AfterCloseEvent object contains CloseAction passed to the view’s close() method. We analyze the close action using the closedWith() method of the event object. Remember: in the previous section, we established a handler for the select action. |
2 | Passes the edited user’s location to the setter of LocationLookupView . |
Launch the application and make sure that the interaction between UserDetailView
and LocationLookupView
is correctly configured.