日々精進

新しく学んだことを書き留めていきます

JSFのconversionフェーズはvalidationフェーズでバリデーションエラーになっても実行される

バリデーションエラーになったらCompositeComponentのgetConvertedValueメソッドは呼ばれないと思っていたら、呼ばれた。まじか。。 以下のようにisValidationFailedをチェックした方が良さそう。

@Override
protected Object getConvertedValue(final FacesContext context, final Object submittedValue) {
    if (FacesContext.getCurrentInstance().isValidationFailed()) {
        return null;
    }
    if (year.getValue() == null || month.getValue() == null || day.getValue() == null) {
        return null;
    }
    ...
}