• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

How to pass parameters or atributtes to a custom validator

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 121
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic