Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with simple validation problem in Struts

 
John Boot
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Boot
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic