1

我需要在日历组件上创建一个验证 - 开始/结束。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>

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

4

1 回答 1

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" />
于 2013-06-23T03:04:00.217 回答