【问题标题】:CommandButton action triggering despite validation errors尽管出现验证错误,仍会触发 CommandButton 操作
【发布时间】:2012-09-14 05:20:43
【问题描述】:

我有一个包含<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" />

当我点击保存按钮时,我可以看到消息弹出,指示该值是必需的,但它随后消失并给我一条消息,指出事务失败。

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

【问题讨论】:

  • 命令按钮和输入文本格式相同?

标签: validation jsf-2 richfaces


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 2014-01-08
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    相关资源
    最近更新 更多