2
votes

I have a simple Struts form. It has a few text fields and a file field. The enctype is multipart/form-data on my form. I validate in the actionform's validate method. If the text fields are empty, I return errors that they are required. Along with the visible fields, I pass a few hidden fields that are needed as request params when the form is processed and returned to the JSP. The JSP needs these request params.

Everything works great when there are no validation errors as the request params get returned by using the ActionRedirect class in the action. But if there are errors returned, I lose the request params. (I am able to access them in the actionform validate method or in the action).

How can I make sure the request params are passed back upon validation error in multipart form? Is there any sort of workaround?

Action-mappings (slightly edited for obfuscation) below:

   <action
    path="/saveQuestion"
    type="blahblahblah.QuestionAction"
    parameter="save"
    name="QuestionForm"
    input="populateQuestion.do"
    scope="request"
    validate="true">
    <set-property property="cancellable" value="true"/>
    <forward name="success" path="viewSurvey.do" redirect="true"/>
  </action>
  <action
    path="populateQuestion"
    type="blahblahblah.QuestionAction"
    parameter="populateRequest"
    name="ItemForm"
    scope="request">
      <forward name="success" path=".editing.Question"/>
  </action>

And my JSP form line:

<html:form styleId="QuestionForm" action="/saveQuestion" enctype="multipart/form-data" method="POST">
1
can you show us the important parts of your code? (for me that would be the related action-mappings in struts-config file) - Th0rndike
Are those hidden fields also properties of the ActionForm? - Jörn Horstmann
Th0rndike I can't paste the code here, but I have the proper input, name, and forwarding. My struts-config.xml is fine... everything works except when I have the multipart/form-data and the validation fails. Horstmann - yes. - eipark
Are you implementing the reset() method in your form? - Claudio
I don't believe so Claudio. - eipark

1 Answers

1
votes

I believe you have two options to solve this problem:

  • Change the scope to session: This way the data will be stored in session and you won't lose any data.
  • Implement the reset method of your validation: This way, when the reset method is called in your validation, you can repopulate the data of the form.

I hope this helps somehow. I might have some other suggestions in my old code files, but i don't have access to them right now. If I have time I'll check them out later.