Announcement Announcement Module
Collapse
No announcement yet.
transfer errors to another jsp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • transfer errors to another jsp

    hi,

    I have 4 input pages, most of the fields on the pages are mandatory but they only need to be filled in and therefor only need to be validated when the user click a submit-button on another page.

    What I would like to happen when the user clicks this button and several fields are not filled in is the following:

    - navigate to the first input-page that has errors and display the field-errors using the <form:error>-tag.
    - when the user then navigates to the next input-page do the same thing again

    My theory on how to do this is is do the final validation in the onSubmit-method of the validate-controller (since I need to controll which ModelAndView to return), store the errors-object in the session and then in each controller for the input-pages check if this object exists in session and copy it to the request.

    I have following (test)code in the validate-controller onSubmit-mehtod:
    Code:
    ValidationUtils.rejectIfEmpty(errors, "sponsor", "error.field.required");
    if (errors.hasErrors()) { request.getSession().setAttribute("errors", errors);
    return new ModelAndView(new RedirectView("projectEditGeneral.htm")); }
    and this in one off the inputpage-controllers:
    Code:
    Object o = request.getSession().getAttribute("errors");
    if (o != null); request.setAttribute(BindingResult.MODEL_KEY_PREFIX + getCommandName(), o);
    but it doesn't work, maybe the key MODEL_KEY_PREFIX is not correct?

    When debugging spring's ErrorTag it simply sais there are no errors so I guess setting this request-attribute did not follow through are is not enough. I don't realy know what's going on but I hope someone else does or can suggest a beter way to address this functional issue?

    many thanks!

  • #2
    Your use case sounds perfect for the AbstractWizardFormController. Otherwise you probably need an overly complex state management.

    Joerg

    Comment


    • #3
      Jörg,

      thanks for your suggestion; the wizard-controller sounds like a good approach but I have never used it before and I'm a bit hesitant using it for this case because of 2 concerns:
      1. my use case is indeed a sequence of input-pages using 1 form (the ideal scenario for a wizard) but they are not completed in 1 go. A user with a certain role must fill in the first 3 pages then those pages are validated and if valid another user must fill in the next page and then another user the next and so on. Although I feel this is still possible with the wizard it's getting more complex to say the least.
      2. I still feel I'll have the same problem with showing the errors. As said the first validation (of the first 3 pages) only occurs after page 3 which is no problem when overriding the validatePage-method. But, does the wizard make it possible to allow the user the navigate through the input pages freely and see the field-errors on each page? I don't think there's a special provision for this? If not, do you think there should be?
      thanks,

      Stijn

      by the way, I did find another solution to the errors-problem: storing it in the session and use a simple custom ErrorTag which gets the field-errors and displays them; works like a charm but if there is some provision in the wizard controller then that would be better.

      Comment


      • #4
        Hi Stijn,

        I'm sorry that I can't help you further since I have never used the AbstractWizardFormController. Your questions go now really into the details so that I can't answer them.

        What I can say is that your multiple user scenario is really unusual. And you can't keep the data/form state in the session since it has to be accessed by another user later on. So you are probably on your own anyway and can't just use Spring's default implementations of the controllers.

        Joerg

        Comment

        Working...
        X