public class WordValidator2 implements Validator, StateHolder {
   /** バリデータID(JSF 設定ファイルと同じ値) */
   public static final String VALIDATOR_ID = "to.msn.wings.jsf.custom.
   WordValidator2";

   private String words = null; // 合言葉リスト

   public void setWords(String words){
   this.words = words;
   }

   public void validate(FacesContext context, UIComponent component,
         Object value) throws ValidatorException {

      if ( context == null ) throw new NullPointerException( "context is null" );
      if ( component == null ) throw new NullPointerException( "component is null" );
      if ( value == null ) {
         return;
      }
      if ( words == null || words.length() == 0 ){
         return;
      }

      String[] wordArray = words.split( "," );

      // 検証処理
      for (int i = 0; i < wordArray.length; i++) {
         if ( wordArray[i].equals( value ) ){
            return;
         }
      }

      throw new ValidatorException( new FacesMessage( "合言葉が違います。" ) );
   }

   public void restoreState(FacesContext context, Object state) {
      words = (String) state;
   }
   public Object saveState(FacesContext context) {
      return words;
   }
}