wood burning stoves 2.0*
The moose likes JSF and the fly likes How to pass parameters or atributtes to a custom validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to pass parameters or atributtes to a custom validator" Watch "How to pass parameters or atributtes to a custom validator" New topic
Author

How to pass parameters or atributtes to a custom validator

Guillermo Nasi
Greenhorn

Joined: Jan 27, 2010
Posts: 3
Hi, I'm trying to make a custom validator but I can't find if there is some way to pass parameters to the validator.
I already googled it but I couldn't find any solution.

Thanks in advance, and I'm sorry for my english.
Guillermo Nasi
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Make your HTML UIComponent(s) properties of your backing bean and bind those components to the bean properties, then you can reference them in the backing bean validator method.


Your custom validator method has a public void methodname(FacesContext, UIComponent, Object) signature. Cast the values to whatever datatype they are supposed to be.


Thanks, leo
Guillermo Nasi
Greenhorn

Joined: Jan 27, 2010
Posts: 3
Hi leo, I think I didn't expalin well enough, the validator is an implementation of the Validator interface provided by JSF, it isn't a method in the backing bean
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Guillermo,

any how you should implement validator interface to write a custom validator component.
in the custom validator, you should override the validate method to write your own logic to validate some blah blah blah.

following is the signature of validate method where in value holds the value you need to validate.
<code>public void validate(FacesContext facesContext, UIComponent uiComponent,
Object value) throws ValidatorException {}</code>


Sun Certified Java Programmer with 93 percent
Guillermo Nasi
Greenhorn

Joined: Jan 27, 2010
Posts: 3
suresh,
i've already implemented the method, my question was if there is some way to send information, like in the lenghtValidator to my own implementation in the jsf like you would do in the range validator or in the lenght validator that comes with jsf implementation.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Guillermo,

I understand your problem, have you created custom validator?
if so, you can add some user defined attributes to the tag that you designed and using that attribute you can send whatever information you need to send to the validator.
I hope this approach will help you.
good luck
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass parameters or atributtes to a custom validator
 
Similar Threads
Struts2 Validation - Number?
Using ValueExpression's in a validator tag
error in custom validation
How to pass form parameters to custom validator
question about struts validator