I have a SimpleFormController, call it AnswerQuestions for our purposes.

This controller gets called over and over (its success view is itself). Each time it gets called, it sets itself up with a different form backing object, one appropriate to the questions being asked in this iteration.

The number of questions vary, and sometimes I have been getting NPE's as my JSP tries to index into questions which aren't there. So, I tried to find out why those questions weren't there.


It turns out that the first time I submit one of these, it's fine. The second time, handleInvalidSubmit is getting called, and as a result I try and create a form backing object for the next group of questions, then that object is used for the current group, and of course NPE's ensue.

I've worked around this using a session variable that I set to let me know which form backing object I should be building, but I would prefer to handle this in less of a hacked up way, especially since it creates problems if I don't clear that session variable once I'm done with it.

My guess is that the first pass through the form, the backing object is written into the session attribute just fine, and then removed when getCommand() is called. For some reason, on the second pass through, the backing object never gets written into the session, therefore handleInvalidSubmit tries to build a new one for me.

Is there something I need to do to ensure the backing object's session gets written in onSubmit, something that it's normally assumed would be done by the success view's showForm() method but that I'm not doing because that's only called once?

TIA for your help,

James