aspose file tools*
The moose likes Struts and the fly likes custom validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "custom validation" Watch "custom validation" New topic
Author

custom validation

Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
Hi,
I want to pass a value to my own validation method. Basically i want to do the same thing as mask or minlength where you tell it a variable name and value. Anyone know how i can access a variable defined in this way?

thanks.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Stu Johns wrote:I want to pass a value to my own validation method.

Which validation method you're using, is it ValidatorForm#validate() method OR Validator Plugin(validator.xml). In former case, you can pass the name=value parameters using 'request' object and accessing them "validate()" method, this is my wild guess and you may not get any success. In later case I don't think we can do this OR I don't know.

Meanwhile, why do you want to this complications ?

HTH.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
I wanted to try and use the validation.xml approach.
It was purely from an educational point of view, I didnt know if it was possible or if the mask validation (and other struts inbuilts) was a special case.

Stu
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Stu Johns wrote:It was purely from an educational point of view,

Then its OK, you can play around with Struts validator framework. Validation is predefined thing which ensures the data is coming the format we wanted, its not a runtime/user wished thing to do
Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
You may have misunderstood the question?
What i'm trying to do was pass a value using the <var-name> and <var-value> tags of <field> in validation-rules.xml
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Stu Johns wrote:You may have misunderstood the question?

Then please elaborate, so that it make some sense?
Stu Johns wrote:What i'm trying to do was pass a value using the <var-name> and <var-value> tags of <field> in validation-rules.xml

Where do you want to "pass the value" ?
Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
I want to use a value I set in the xml file in a method i am using to do the validation.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you writing a custom validator, or writing a validate() method in your action form? If the latter, then AFAIK you don't have access to anything in the validation config.

If the former, follow the example in the documentation.

http://struts.apache.org/1.2.9/userGuide/dev_validator.html

(You neglected to mention which version of Struts you're using.)
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

hmm hard to do, but there are NO classes I saw in Struts API which can have an access to validatore.xml which returns the <field> element,t still have look at this method, may this methods put some light. OR I don't know much about your requirement
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It's not hard to do at all. The link I supplied shows precisely how to do it. It's not Struts, it's commons validator.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You may be right David, but the thing is I didn't understand the authors requirement, and what I concluded finally was, the author want to get the <var-name> and <var-value> from validator.xml for the specific bean/form.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's what I thought, too, and that's what custom validators do, as does the example on the validation doc page.
Stu Johns
Ranch Hand

Joined: Aug 11, 2008
Posts: 63
Thanks,
I've found what i was after in the link. The bit i needed was field.getVarValue
Thanks for your help guys (and patience)

Stu
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Stu Johns wrote:Thanks for your help guys (and patience)

Major credits goes to David, I was just wondering here and there
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: custom validation