r/JavaFX • • Dec 04 '24
Discussion Dialogs in MVVM
There was recently a post how to display dialogs in MVCI. But what about dialogs in MVVM? It's actually not a simple question. For example, I decided to use dialog service, that knows and uses view:
in View:
viewModel.setDialogService(new DialogServiceImpl(this));In ViewModel:
var result = this.dialogService.openSomeDialog(someDialogVM);For example, we have a dialog that consists of AlertView and AlertViewModel. Now FooViewModel wants to show this dialog. FooViewModel knows only AlertViewModel but it doesn't know AlertView. So, we create a DialogService that is available in FooViewModel, something like
public interface FooDialogService extends DialogService {
void openAlertDialog(AlertViewModel dialogVM);
}and after that in FooViewModel
this.dialogService.openAlertDialog(alertVM)So, FooDialogService knows FooView and AlertView and has instance of AlertViewModel.
And what solution do you use?
View all comments
Show parent comment
1
u/[deleted] Dec 04 '24 edited Dec 04 '24
DialogService is "our" solution to display dialogs from
ViewModel. The question is how to invoke it fromViewModel. I updated my post to make things clearer. Thank you.