Hi,

I'm looking for advice as to the correct place to catch and display persistence related errors to the user.

I've got a working application with views, controllers, DAO and model layers. Currently I am just using application-context XML to populate beans in the model layer. Above that I have a DAO layer that returns requested model beans as it would were I using a database for persistence. Above the DAO layer is a layer of controllers that handle user requests, retrieve the data from DAOs and return views to display the data.

I've overwritten:
1) The formBakcingObject(request) to retrieve the requested record ID from the request object, load the record using the DAO and return the backing object;
2) The onSubmit(request, response, command, errors) to invoke the store method on the DAO and return a success view.

In both cases the DAO can throw errors (such as RecordNotFoundException or DuplicateKeyValueException, etc.). I need to catch those in the controller and display the form (view) to the user with the error message.

First I tried calling errors.reject("some message") in the onSubmit method and returning the same formView to display the form with the errors, as would be done if the validator failed a field. This did not work as the form could not find the new command object with the errors.

Then I saw in the API docs that doSubmitAction is the right place to do this kind of IO and not the doSubmit method, but this method does not have access to the errors object.

The questions are:
1) Where is the right place to perform the following actions:
a) Retrieving the data and catch the RecordNotFoundException
b) Persisting the form data and catch the DuplicateKeyException
2) How do I display the above errors to the user, preferably on the data capture form.

Thanks very much for you assitance.

Regards,
Stefan