Typically the execStore() function of the a formHandler look like this:
@Override
protected void execStore() throws ProcessingException {
IExampleService service = SERVICES.getService(IExampleService.class);
ExampleFormData formData = new ExampleFormData();
exportFormData(formData);
formData = service.store(formData);
}
If something goes wrong an exception is triggered. It produces a MessageBox and for the user the form is leaved touched (meaning Form#isSaveNeeded() will still be true).
I work with another pattern because I need to import error markers from the server in the client application. This works fine, but I have no possibility to tell scout that the form was not stored server-side.
If you look at AbstractForm#storeStateInternal() implementation you notice that the m_formStored flag is used to indicate that the form was'nt stored:
protected void storeStateInternal() throws ProcessingException {
//...
try {
rebuildSearchFilter();
m_searchFilter.setCompleted(true);
getHandler().onStore();
execStored();
}
catch (ProcessingException e) {
// clear search
if (m_searchFilter != null) {
m_searchFilter.clear();
}
// store was not successfully stored
m_formStored = false;
throwVetoExceptionInternal(e);
//...
I was thinking I can do something like this in my execStore():
@Override
protected void execStore() throws ProcessingException {
//call server
if <error marker in formData> {
//special logic: import error markers on the fields
setFormStored(false);
} else {
//default case
}
}
The problem is that the current implementation really expects that an Exception is raised if the form was not saved server-side.
See the doSave() implementation:
//...
try {
m_closeType = IButton.SYSTEM_TYPE_NONE;
// ensure all fields have the right save-needed-state
checkSaveNeeded();
validateForm();
m_closeType = IButton.SYSTEM_TYPE_SAVE;
if (isSaveNeeded()) {
storeStateInternal();
markSaved();
}
}
//...
In my opinion the markSaved() call should only occurred if isFormStored() returns true.
This could be changed and ensured with a unit test.
What do you think?
Should I open a bug?