Struts Server-Side Form Validation

Discussion in 'Java' started by timmac, Dec 16, 2004.

  1. timmac

    timmac Guest

    I'm hoping someone can help me with form validation using struts and
    the commons validator. I have everything set up, and as far as I can
    tell, it's identical to examples I've seen elsewhere. Client-side
    (javascript) validation works fine, but when I attempt server-side
    validation, it seems to perform no validation at all.

    Any ideas?

    The relevant portion of my struts-config.xml is:

    <form-beans>
    <form-bean name="registerFormBean"
    type="com.pixel.pool.RegisterFormBean" />
    </form-beans>
    ......

    <action path="/register" forward="/register.jsp" />
    <action path="/register-submit"
    type="com.pixel.pool.Register"
    name="registerFormBean"
    scope="request"
    validate="true"
    input="input">
    <forward name="input"
    path="/register.do" />
    <forward name="success"
    path="/thankYou.jsp" />
    </action>


    I have the RegisterFormBean class extending ValidatorForm as well.
    Anyone know what I'm missing?

    Thanks in advance,
    Tim MacDonald
    timmac, Dec 16, 2004
    #1
    1. Advertising

  2. timmac

    Sudsy Guest

    timmac wrote:
    <snip>
    > I have the RegisterFormBean class extending ValidatorForm as well.
    > Anyone know what I'm missing?


    Do you have the plug-in defined in the struts-config.xml file? Do you
    have the field validations specified in one of the files named in the
    pathnames property?
    Sounds basic, I know, but these elements are essential...
    Sudsy, Dec 16, 2004
    #2
    1. Advertising

  3. timmac

    timmac Guest

    In my struts-config.xml file, I have:

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"

    value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    <set-property property="stopOnFirstError" value="true" />
    </plug-in>

    And, in my validation.xml file, I have:

    <form-validation>
    <formset>
    <form name="registerFormBean">
    <field property="firstName"
    depends="required">
    <arg0 key="registerFormBean.firstName" />
    </field>
    <field property="lastName"
    depends="required">
    <arg0 key="registerFormBean.lastName" />
    </field>
    <field property="age"
    depends="required,integer">
    <arg0 key="registerFormBean.age"/>
    </field>
    </form>
    </formset>
    </form-validation>

    What gets me is that client-side validation seems to work fine,
    suggesting (in my naivety) that the definitions are probably all
    correct.

    Thanks so much for any further assistance you can offer!
    -Tim MacDonald
    timmac, Dec 16, 2004
    #3
  4. timmac

    timmac Guest

    In my struts-config.xml file, I have:

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"

    value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    <set-property property="stopOnFirstError" value="true" />
    </plug-in>

    And, in my validation.xml file, I have:

    <form-validation>
    <formset>
    <form name="registerFormBean">
    <field property="firstName"
    depends="required">
    <arg0 key="registerFormBean.firstName" />
    </field>
    <field property="lastName"
    depends="required">
    <arg0 key="registerFormBean.lastName" />
    </field>
    <field property="age"
    depends="required,integer">
    <arg0 key="registerFormBean.age"/>
    </field>
    </form>
    </formset>
    </form-validation>

    What gets me is that client-side validation seems to work fine,
    suggesting (in my naivety) that the definitions are probably all
    correct.

    Thanks so much for any further assistance you can offer!
    -Tim MacDonald
    timmac, Dec 16, 2004
    #4
  5. timmac

    timmac Guest

    In my struts-config.xml file, I have:

    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"

    value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    <set-property property="stopOnFirstError" value="true" />
    </plug-in>

    And, in my validation.xml file, I have:

    <form-validation>
    <formset>
    <form name="registerFormBean">
    <field property="firstName"
    depends="required">
    <arg0 key="registerFormBean.firstName" />
    </field>
    <field property="lastName"
    depends="required">
    <arg0 key="registerFormBean.lastName" />
    </field>
    <field property="age"
    depends="required,integer">
    <arg0 key="registerFormBean.age"/>
    </field>
    </form>
    </formset>
    </form-validation>

    What gets me is that client-side validation seems to work fine,
    suggesting (in my naivety) that the definitions are probably all
    correct.

    Thanks so much for any further assistance you can offer!
    -Tim MacDonald
    timmac, Dec 16, 2004
    #5
  6. timmac

    Sudsy Guest

    timmac wrote:
    <snip>

    Two things:
    1. Validation requires that your class extend one of the Validator
    classes, e.g. ValidatorForm. Those have an implementation of the
    validate method which will utilize the validations you specify
    (which look to be fine, BTW).
    2. The input attribute of the action element in struts-config.xml
    should point to a page which will be displayed if validation fails.
    This is often the same as the page which submitted to the action
    in the first place.

    For more, I've written an article which discussed some of these
    concepts. You can find it here:
    <http://www.sudsy.net/technology/validation.html>
    Sudsy, Dec 16, 2004
    #6
  7. timmac

    timmac Guest

    I do have my RegisterFormBean class extending the ValidatorForm, and
    implementing Serializable

    Changing the input attribute of the <action> element doesn't seem to
    make any difference. (As an interesting aside, the registration form
    example that ships with struts, and seems to work fine, uses
    input="input" as I had done, where input is defined as a forward)

    I am very appreciative of all your suggestions... I don't suppose you
    know anything else that could be wrong?

    Thanks,
    Tim M.
    timmac, Dec 16, 2004
    #7
  8. timmac

    Sudsy Guest

    timmac wrote:
    > I do have my RegisterFormBean class extending the ValidatorForm, and
    > implementing Serializable
    >
    > Changing the input attribute of the <action> element doesn't seem to
    > make any difference. (As an interesting aside, the registration form
    > example that ships with struts, and seems to work fine, uses
    > input="input" as I had done, where input is defined as a forward)
    >
    > I am very appreciative of all your suggestions... I don't suppose you
    > know anything else that could be wrong?


    Give me a chance to get my test Tomcat environment up and running and
    I'll give your code a test...
    Sudsy, Dec 16, 2004
    #8
  9. timmac

    timmac Guest

    Thank you very much!
    timmac, Dec 16, 2004
    #9
  10. timmac

    Ryan Stewart Guest

    "timmac" <> wrote in message
    news:...
    >I do have my RegisterFormBean class extending the ValidatorForm, and
    > implementing Serializable
    >
    > Changing the input attribute of the <action> element doesn't seem to
    > make any difference. (As an interesting aside, the registration form
    > example that ships with struts, and seems to work fine, uses
    > input="input" as I had done, where input is defined as a forward)
    >
    > I am very appreciative of all your suggestions... I don't suppose you
    > know anything else that could be wrong?
    >
    > Thanks,
    > Tim M.
    >

    What version of Struts are you using?
    Ryan Stewart, Dec 17, 2004
    #10
  11. timmac

    timmac Guest

    1.2.4

    Thanks!
    timmac, Dec 17, 2004
    #11
  12. timmac

    timmac Guest

    Okay, I finally found the problem, well, a fix anyway. Re deploying
    the web application in the AppServer admin seems to do the trick...
    *sigh*. Even restarting the appserver isn't sufficient, ironically.
    Thank you very much for all of your help!
    timmac, Dec 17, 2004
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,678
    Colin Mackay
    Jun 25, 2003
  2. Matt
    Replies:
    14
    Views:
    4,071
    Chad Z. Hower aka Kudzu
    Jan 30, 2004
  3. =?Utf-8?B?dmlkeWE=?=
    Replies:
    1
    Views:
    741
    Kevin Spencer
    Jun 2, 2005
  4. David McDivitt

    struts server side validation

    David McDivitt, May 13, 2004, in forum: Java
    Replies:
    2
    Views:
    6,492
    amarnath_it
    Sep 11, 2007
  5. Sumith Mathur
    Replies:
    0
    Views:
    2,190
    Sumith Mathur
    Sep 23, 2004
Loading...

Share This Page