public class WordValidator implements Validator { 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;
List wordList = new ArrayList(); // 合言葉の一覧 wordList.add( "山" ); wordList.add( "川" );
// 検証処理 if ( !wordList.contains( value ) ){ throw new ValidatorException( new FacesMessage( "合言葉が違います。" ) ); } } }