I am doing code review and bug correction in a Scout Application.
I have seen this today and wanted to share it with you:
@Override
protected void execStore() throws ProcessingException {
int button = MessageBox.showYesNoMessage(TEXTS.get("MessageBoxTitle"), TEXTS.get("ConfirmSave"), null);
if(button == MessageBox.YES_OPTION) {
IMyService service = SERVICES.getService(IMyService.class);
MyFormData formData = new MyFormData();
exportFormData(formData);
formData = service.store(formData);
}
}
What is wrong with this code snippet?
If the user clicks on "No" in the dialog, nothing is sent to the server... This is what the developer wanted.
But the problem is that when the user clicks no, the scout client will consider the form as stored.
With Scout 4.1.0-SNAPSHOT (work in progress for the Eclipse Scout Mars release) you can do this:
@Override
protected void execStore() throws ProcessingException {
int button = MessageBox.showYesNoMessage(TEXTS.get("MessageBoxTitle"), TEXTS.get("ConfirmSave"), null);
if(button == MessageBox.YES_OPTION) {
IMyService service = SERVICES.getService(IMyService.class);
MyFormData formData = new MyFormData();
exportFormData(formData);
formData = service.store(formData);
} else {
setFormStored(false);
}
}
If you are on the Luna Branch, Bug 437361 is not included in the framework. Just do the same by hand:
@Override
protected void execStore() throws ProcessingException {
int button = MessageBox.showYesNoMessage(TEXTS.get("MessageBoxTitle"), TEXTS.get("ConfirmSave"), null);
if(button == MessageBox.YES_OPTION) {
IMyService service = SERVICES.getService(IMyService.class);
MyFormData formData = new MyFormData();
exportFormData(formData);
formData = service.store(formData);
} else {
VetoException e = new VetoException("Form was not stored");
e.consume();
throw e;
}
}
By the way, if you want to ask something to the user, I think that AbstractFormHandle#execValidate() is a better place to do it:
@Override
protected boolean execValidate() throws ProcessingException {
return MessageBox.showYesNoMessage(TEXTS.get("MessageBoxTitle"), TEXTS.get("ConfirmSave"), null) == MessageBox.YES_OPTION;
}
I hope this helps...
[Updated on: Tue, 02 September 2014 16:49]
Report message to a moderator