wood burning stoves 2.0*
The moose likes Struts and the fly likes Group variable validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Group variable validation" Watch "Group variable validation" New topic
Author

Group variable validation

sriraj anandhi
Greenhorn

Joined: Jul 30, 2006
Posts: 2
Guru's

I have a issue with a group variable validation using struts commons validation, any help will be appreciated.

I have a phone field (it is made of 4 text fields 3-3-4-5, last field being for extension)

eg. 646-787-7868-98989

I having tough time creating a validation rule for it.

the rules are:
1. All text fields should be numeric
2. Phone (all combined) is a required field
2. Ext field is optional

Please help.

thanks
raj
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
just make the first 3 fields required and integer. The last field is integer.


Merrill
Consultant, Sima Solutions
sriraj anandhi
Greenhorn

Joined: Jul 30, 2006
Posts: 2
Thanks for the reply, but my problem is I want to display the error message for the full phone number only once. As the the phone number is captured in separate fields I getting the error message four times.

Any help will be appreciated.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you use the Struts validation framework and define four fields, you're going to get four error messages. There's no way around this with the "out of the box" validation framework.

You have 2 choices:

1-Remove the validation rules for all four fields. Then override the validate() method of your ActionForm. Manually code the logic for this validation, then call super.validate() to handle the other validation framework validations.

2-Create a custom validation rule that will handle this situation.

This link gives an example of how to code a custom validation rule.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Group variable validation
 
Similar Threads
Date Difference
Java data validation
Please help
Multiple Error messages for Single regex validation
struts validator. stoping on first validation error.