• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass parameters or atributtes to a custom validator

 
Guillermo Nasi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Guillermo Nasi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>

 
Guillermo Nasi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic