• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Different use of validator

 
Bartender
Posts: 2180
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , everyone
Let me give you a hint about validator. We have to memorize the 4 different usage of validator attribute.
1. CDI validator.
For example


@Named ("xxxValidator")
public class XXXValidator implements Validator{

@Override
public void validate(FacesContext context, UIComponent compoent, Object object) throws ValidatorException {....}
}



  <h:inputText ... >
      <f:validator binding="#{xxxValidator}"/>

 </h:inputText>



2. Use @FacesValidator


@FacesValidator ("xxxValidator")
public class XXXValidator implements Validator{

@Overrides
public void validate (FacesContext context, UIComponent component, Object value) throws ValdiatorException{

   ....
}
}



   <h:inputText ...>

         <f:validator validatorId="xxxValidator"/>
   </h:inputText>



3. Use validator defined in faces-config.xml
For example,


package com.practice;
 public class XXXValidator implements Validator{

    @overrides
     public void validate (FaceContext context, UIComponent component, Object value) throws ValidatorException{
         ...

     }

  }
 In faces-config.xml
<validator>
           <validator-id>customValidator</validator-id>
           <validator-class>com.practice.XXXValidator</validator-class>    //make sure it is a fully qualified name
 </validator>

 <h:inputText ...>
           <f:validator validatorId="customValidator"/>
 </h:inputText>



4. Use bean validator


   @Named ("myBean")
   public class examBean {
 
    public void validateExamName (FacesContext context, UIComponent component, Object value) throws ValidateException {...}

   }

<h:inputText ... validator="#{myBean.validateExamName}">



2 and 3 are the same except that one uses annotation while another one uses faces-config.xml
1 , 2, 3 uses <f:validator> facelet. When you are using CDI validator, you use binding = "validator name" When you are using validator, you use validatorId="validator id".
4 is different as the bean itself has its own validator method taking FacesContext, UIComponent and Object as arguments.

In the exam, you may be asked to change from case 1 to case 4, or something like that.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic