日々精進

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

JSFのcomposite componentでpostValidateEventが呼ばれない

以下のようにcomposite component内に<f:event listener="#{cc.validate}" type="postValidate" />を入れてもlistenerが呼ばれなかった。

<ui:component
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:cc="http://java.sun.com/jsf/composite">
    <cc:interface componentType="inputDate">
        <cc:attribute name="value" type="java.util.Date" shortDescription="The selected time. Defaults to now."/>
    </cc:interface>
    <cc:implementation>
        <f:event listener="#{cc.validate}" type="postValidate" />
        <span id="#{cc.clientId}" style="white-space:nowrap">
            <h:inputText id="day" binding="#{cc.day}" styleClass="inputText inputText-date">
                <f:ajax event="change" execute="#{cc.clientId}" />
            </h:inputText>日
            <h:message for="day" styleClass="errorMessage"/>
        </span>
    </cc:implementation>
</ui:component>

原因は結局わからず、f:validatorタグを使ってバリデーションを行った。 f:validatorタグを使って複数の入力項目に対してバリデーションをかける場合は対象の項目のうち一番下の項目にvalidatorタグを付けること。 validatorタグより下の項目の値はvalidateメソッドから取れないらしい。

参考: