Hi
I am new to Vaadin Flow.
I have created a Modal Dialog to confirm whether the user is sure about their change, however the record is saved as the java logic continues even though the dialog is displayed.
Java/Swing the program flow would stop until the dialog is closed.
Hi @pjc158, opening a modal dialog restricts interaction to just this dialog but doesn’t pause the server-side program. For what you describe, consider using Confirm Dialog in which you can subscribe to the confirm action and specify what to do next when the user confirms or cancels the action. For example:
ConfirmDialog dialog = new ConfirmDialog();
dialog.setHeader("Unsaved changes");
dialog.setText("There are unsaved changes. Do you want to discard or save them?");
dialog.setCancelable(true);
dialog.addCancelListener(event -> {
// By default it just closes the dialog
});
dialog.setConfirmText("Save");
dialog.addConfirmListener(event -> {
// Save the record here
});
Please refer to the documentation to learn more about Confirm Dialog.
Hi
That’s a bit of a pain, as I need to validate at least 10 fields (or more for some records), if the validation fails for one or more I do not want to save the record as the user has to correct the issue first.
Hi
To keep it simple I have decided to add change listener to those fields that needs validating and show a config dialog, and then validate the rest of the fields at the end before saving the record.
However if I find an issue ask them to confirm the change and if they say no how do I force Vaadin to not leave the field or force it back to that field?
termsDays_NUMF.addValueChangeListener(event → {
if (event.getValue() != null) {
if (creditTerms_FF.creditTerms_FM != null) {
if (creditTerms_FF.creditTerms_FM.validate_termsDays() == false) { // re-input value code here
}
}
}
});
This is a fundamental difference between single threaded desktop application (Swing) and distributed system of the web application (Server and Browser are different machine). Hence the web applications follow event driven paradigm.
Your question is quite frequently popping up, and is something that requires some un-learning and re-learning. Respectively it means doing differently when converting Swing app to Web application.
It depends what we mean by “bean”. Binder is not restricted to “beans” like data base entities. It can be used with any POJO or even with a Map.