尽管验证错误,CommandButton操作仍会触发

时间:2012-09-21 18:44:49

标签: validation jsf-2 richfaces

我有一个页面,其中包含<input type="text">属性集的required="true"个字段。我还有一个提交表单的保存按钮。

不幸的是,即使required="true"字段留空,表单也会提交。

这是我目前的代码:

<s:decorate template="layout/edit.xhtml" id="decAQty">
    <ui:define name="label">Actual Qty Received</ui:define>
    <h:inputText
        value="#{tktReceivingInfoHome.instance.actualReceivedQty}"
        required="true" id="txtAQty"
        converterMessage="Not a valid Quantity">
        <a:ajax event="blur" render="txtAcTotal,decAQty"
            listener="#{returnsReceivingManager.setActualTotal}" />

    <h:messages id="error" style="display:none" />
    </h:inputText>

<a:commandButton id="btnSave"
    action="#{returnsReceivingManager.checkQtyDiff}" value="Save"
    render="decSQty,decScQty,decRtvQty,addForm,decAQty,decRecdDate,decRecWH,decErrorRMA,decErrorRTV,decReason,decStatusRMA,decStatusRTV,decPriority,decResolution"
    oncomplete="#{returnsReceivingManager.rmaInfo.qtyDiff!=0 ? '#{rich:component(\'addPanel\').show();' : 'callSave();'}"
    onclick="showProgressBar()" />
<a:jsFunction action="#{returnsReceivingManager.save}"
    oncomplete="hideProgressBar()" name="callSave" />

当我点击保存按钮时,我会看到弹出的消息,指示该值是必需的,但它会消失并给我一条消息,说明交易失败。

换句话说,该页面似乎已提交两次。我喜欢社区可以提供的有关如何解决此问题的任何建议。

1 个答案:

答案 0 :(得分:0)

目前仅在离开txtAQty字段(模糊事件)时触发验证。这就是您看到错误消息的原因。接下来发生的是单击“保存”按钮,该按钮执行某些字段的重新渲染,但不对任何字段进行处理(包括验证)。这就是错误消失的原因。

您应该将process属性添加到commandButton,其值至少列出txtAQty字段(但更好的是您要重新渲染的所有其他字段)

相关问题