• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

strut validation frame work issue

 
prafull kherde
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The better option is to use the Validate method in the form bean.
 
prafull kherde
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then what should i use or how should i resolve the problem
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic