0

Assume I have an action to validate a form. If this method returns success, it is being redirected to a new action with all its parameters. One of my parameters is of type:

java.io.File

And this causes the redirected action to return INPUT instead of SUCCESS.

Here's my code:

   public String validateMemberForm() {
    int fails = 0;
    if (service.findMemberByCompany(company) != null) {
        addFieldError("company", "This company is already registered!");
        fails++;
    }
    if (service.findMemberByEmail(email) != null) {
        addFieldError("email", "This email is already registered!");
        fails++;
    }
    if (fails != 0) {
        return INPUT;
    }
    return SUCCESS;
}

My redirect inside struts.xml:

<action name="validate_member" class="managementAction" method="validateMemberForm">
        <result name="success" type="redirectAction">
            <param name="actionName">create_member</param>
            <param name="company">${company}</param>
            <param name="upload">${upload}</param> <!-- THIS PARAM IS OF TYPE FILE -->
            <param name="uploadContentType">${uploadContentType}</param>
            <param name="uploadFileName">${uploadFileName}</param>
            <param name="email">${email}</param>
        </result>
        <result name="input">/pages/authenticated/memberSave.jsp</result>
    </action>

And my 'create_member' action returns INPUT.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Bravo
  • 1,944
  • 4
  • 29
  • 53
  • Not to be overtly picky but why not just use: public void validate() method to contain your field error code? See: http://struts.apache.org/release/2.3.x/docs/form-validation.html then you don't need the redirect and the action dedicated to validation only. – Quaternion Dec 02 '14 at 19:34
  • HTTP params are strings. You can't redirect with a file in any meaningful way. – Dave Newton Dec 02 '14 at 19:59
  • Thanks. @Quaternion I want my class to contain more than one actions, that's why I do not use void validate(). – Bravo Dec 02 '14 at 22:37
  • You can use the validateXxx() form to include multiple validation methods into one class... Dave pointed out the redirect limitation but if you insist on this separation you could chain... – Quaternion Dec 02 '14 at 23:47
  • Cheers @Quaternion. Didn't know about this approach, this has solved my problem. – Bravo Dec 03 '14 at 00:25
  • @Bravo related: http://stackoverflow.com/a/27114916/1654265 – Andrea Ligios Dec 03 '14 at 08:44

0 Answers0