GeeCON Prague 2014*
The moose likes Struts and the fly likes strut validation frame work issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "strut validation frame work issue" Watch "strut validation frame work issue" New topic
Author

strut validation frame work issue

prafull kherde
Greenhorn

Joined: Jun 04, 2007
Posts: 12
Can any body solve my problem.
I am using strut validation frame work.

I have four input field's for all input field's it shows fore massage's of validation if they are empty but I want only one massage if all the fields are empty and if any one of four is not empty then the common massage.
Like when any one field is empty then it will show the massage for those fields�s only.
Is it possible in strut to show single massage if all the fields are empty. (ex: All * field are required)

I am new to strut.
I try to use validwhen and dependantFields but this doesn�t work it out.
Is there any other way to do it?
Mohit Chadha
Ranch Hand

Joined: Feb 04, 2007
Posts: 264
The better option is to use the Validate method in the form bean.
prafull kherde
Greenhorn

Joined: Jun 04, 2007
Posts: 12
ya thanks Mohit.

But if I override the validate method should I able to use the xml validation implementation also if it is so then how to do it.

For all empty field I want to override the validate method but for other thing I want to use the xml validation.
Mohit Chadha
Ranch Hand

Joined: Feb 04, 2007
Posts: 264
Originally posted by prafull kherde:
ya thanks Mohit.

But if I override the validate method should I able to use the xml validation implementation also if it is so then how to do it.

For all empty field I want to override the validate method but for other thing I want to use the xml validation.


You can use both the XML validation and the form bean Validate method you need to only override the Validate method(for all the empty fields condition) and have the other Validations in the XML file.
prafull kherde
Greenhorn

Joined: Jun 04, 2007
Posts: 12
Thanks again for your valuable suggestion,
I try to override the validate method but I am not allowed to change there so I wrote my own validation rule.

Now my validation rule is working but I am not able to stop the validation for other fields.
Like there is one variable in org.apache.struts.validator.ValidatorPlugIn that is stopOnFirstError if it is set to true at runtime then may be I will able to stop the strut validation
what would you suggest.
[ June 11, 2007: Message edited by: prafull kherde ]
Mohit Chadha
Ranch Hand

Joined: Feb 04, 2007
Posts: 264
stopOnFirstError is used for indicating whether JavaScript validation should stop when it finds the first error or continue validation. I don't think it will be useful for you.
prafull kherde
Greenhorn

Joined: Jun 04, 2007
Posts: 12
then what should i use or how should i resolve the problem
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by prafull kherde:
Is it possible in strut to show single massage if all the fields are empty. (ex: All * field are required)

No, it's not. You'd have to make custom modifications to the framework in order to do this.

Your choices are:
A. Use Validation framework and make custom modifications to it
B. Use the validate() method in your ActionForm
C. Just live with the multiple messages.


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
try to override the validate method but I am not allowed to change there so I wrote my own validation rule.

hmmm...I don't quite understand what you are saying there. If you want to use both your own validation code and the validator framework you just need to be sure to call super.validate() in your validate method. If you don't want to perform the other validation if all the fields are blank then don't call super.validate(). Something like this:


- Brent
prafull kherde
Greenhorn

Joined: Jun 04, 2007
Posts: 12
Thanks Brent,


try to override the validate method but I am not allowed to change there

Means our customer don�t allow us to change there in from bean or to override the validate() method.

Because of that I have written my own validation rule but in that method I want to stop the strut validation for other fields if my own validation rule fails.
If you didn�t get it just replay me so that I can elaborate on that.



Thanks
Prafull
[ June 25, 2007: Message edited by: prafull kherde ]
 
GeeCON Prague 2014
 
subject: strut validation frame work issue