• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Help with simple validation problem in Struts

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic