Results 1 to 2 of 2

Thread: Correct place to display persistence related errors

  1. #1
    Join Date
    Apr 2005
    Posts
    19

    Default Correct place to display persistence related errors

    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

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    1.a) in formBackingObject, like you already do
    1.b) in onSubmit, like you already do

    So that's not where your problem is :-)

    The problem is that the "flow" implemented in SimpleFormController does not expect any errors during formBackingObject() or onSubmit() if validation was successful. I suggest you override the processFormSubmission() method and implement the appropriate workflow for your needs: that will solve question 2.

    Erwin

Similar Threads

  1. Validation Errors will not display
    By thus in forum Web
    Replies: 1
    Last Post: Oct 18th, 2005, 04:40 PM
  2. Replies: 2
    Last Post: Apr 29th, 2005, 03:43 AM
  3. Replies: 2
    Last Post: Apr 28th, 2005, 02:01 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •