This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes Help with simple validation problem in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Help with simple validation problem in Struts" Watch "Help with simple validation problem in Struts" New topic
Author

Help with simple validation problem in Struts

John Boot
Greenhorn

Joined: Jul 22, 2004
Posts: 12
Hi,

Can someone help me with the following simple validator
problem in Struts??

I have modified the simple logon application from the
book 'Struts in Action' to use validation framework.

Basically only 2 fields to validate in a form.
1 field named username, the other named password.
Both are required and have maximum length of 8.

The follwing is my validation.xml

<form-validation>
<formset>
<form name="logonForm">
<field property="username" depends="required,maxlength">
<msg name="required" key="error.username.required"/>
<arg0 name="maxlength" key="Username" resource="false"/>
<arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>8</var-value>
</var>
</field>
<field property="password" depends="required,maxlength">
<msg name="required" key="error.password.required"/>
<arg0 name="maxlength" key="Password" resource="false"/>
<arg1 name="maxlength" key="${var:maxlength}"resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>8</var-value>
</var>
</field>
</form>
</formset>
</form-validation>

---------------------

My application.properties file

error.username.required=Username is required
error.password.required=Password is required
errors.maxlength={0} can not be greater than {1} characters.

Problem:

Scenarios

* Nothing on username and password fields
Works ok, got pop-up display:
Username is required
Password is required

* username: 123456789
password: // Nothing
Got pop-up display:

Username can not be greater than 8 characters.

Why no message on password?? i.e. Password is required

* Revers scenario of above case

* username: 11
password: 123456789
Got server side validation message instead as below in browser!!!

Password can not be greater than 8 characters.

Even though, username field validation passed, password field
didn't. I wud expect a pop-up message in clien side validation.
Why is this the case???

* Revers scenario of above case

-----------

It doesn't look like client side validation can do both fields
except in the first case where both fields are empty.

Is there something wrong with my validation.xml or is it normal??

Thanks


John Boot
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

the validation.xml looks ok to me. I'm not much of an expert on the framework's workings in the javascript realm.

Not to avoid the problem or anything, but it might be a good idea to set the maxlength attribute on your textfields.


A good workman is known by his tools.
John Boot
Greenhorn

Joined: Jul 22, 2004
Posts: 12
Correction to my problem description, I said

* username: 11
password: 123456789
Got server side validation message instead as below in browser!!!

Password can not be greater than 8 characters.

Even though, username field validation passed, password field
didn't. I wud expect a pop-up message in clien side validation.
Why is this the case???

Now there is no reverse of above problem, it seems if username field
pass client side validation, it is passed right to server validation
regardless of password validity on client side.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with simple validation problem in Struts