焦点丢失后触发OmniFaces多场验证

时间:2013-06-23 00:39:36

标签: ajax validation jsf jsf-2 omnifaces

我需要在Calendar组件上创建验证 - 开始/结束。 OmniFaces非常支持多字段验证,例如:

<h:panelGrid columns="3">

    <h:outputLabel for="startDate" value="Start date" />
    <h:inputText id="startDate" value"#{booking.reservation.startDate}" required="true"
        requiredMessage="Please enter start date"
        converterMessage="Please enter format yyyy-MM-dd">
        <f:convertDateTime pattern="yyyy-MM-dd" />
    </h:inputText>
    <h:message for="startDate" />

    <h:outputLabel for="endDate" value="End date" />
    <h:inputText id="endDate" value"#{booking.reservation.endDate}" required="true"
        requiredMessage="Please enter end date"
        converterMessage="Please enter format yyyy-MM-dd">
        <f:convertDateTime pattern="yyyy-MM-dd" />
    </h:inputText>
    <h:panelGroup>
        <h:message for="endDate" />
        <h:message for="order" />
        <o:validateOrder id="order" components="startDate endDate" 
            message="End date must be after start date" />
    </h:panelGroup>

</h:panelGrid>

<h:commandButton value="submit" action="#{booking.submit}">
    <f:ajax execute="@form" render="@form" />
</h:commandButton>

但是,在此示例中,手动提交后会触发验证。我需要在焦点(日历)丢失后进行验证。我怎样才能做到这一点?感谢。

1 个答案:

答案 0 :(得分:1)

OmniFaces中的多字段验证器可以在<f:ajax execute>中引用。 “焦点丢失”事件是blur事件。因此,这应该做:

<h:inputText ...>
    <f:ajax event="blur" execute="startDate endDate order" render="m_startDate m_endDate m_order" />
</h:inputText>

其中m_startDate等是<h:message>组件的ID,如此

<h:message id="m_startDate" for="startDate" />