Struts Server-Side Form Validation

T

timmac

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
 
S

Sudsy

timmac wrote:
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...
 
T

timmac

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
 
T

timmac

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
 
T

timmac

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
 
S

Sudsy

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>
 
T

timmac

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.
 
S

Sudsy

timmac said:
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...
 
R

Ryan Stewart

timmac said:
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?
 
T

timmac

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top