【问题标题】:Why is validation not run within second form?为什么验证不在第二种形式中运行?
【发布时间】:2013-08-17 10:01:00
【问题描述】:

带有自己的表单的(Richfaces)弹出窗口提供了一个保存按钮,该按钮必须执行另一个表单 (contentForm),并且在发生验证失败时不转发。

但是,saveHandler.forward() 总是被调用...有什么想法吗?

<a4j:commandButton 
    id="saveContentChanges" 
    value="Speichern" 
    action="#{cc.attrs.handler.save()}"
    type="submit"> 
    <a4j:ajax 
        execute=":contentForm" 
        render=":contentForm"
        oncomplete="if (#{!facesContext.validationFailed}) { saveHandler.forward() } else { #{rich:component('contentSaveHandlerPopup')}.hide() }"
        onerror="errorHandler.onError(event.description); #{rich:component('contentSaveHandlerPopup')}.hide();" />
</a4j:commandButton>

附言。此代码位于复合组件中。我在 JavaScript 控制台上没有收到任何错误。

【问题讨论】:

    标签: ajax jsf-2 richfaces ajax4jsf


    【解决方案1】:

    在 HTML 中,只能提交单个表单,因此在您的情况下,只有来自 a4j:commanButton 所在表单的数据从客户端提交到服务器。 execute 属性仅影响服务器端处理,它不会改变数据的提交方式。因此,向execute 添加一个不同的表单使其实际在服务器端进行处理,但由于没有提交的值,这意味着没有什么要验证的。

    替代解决方案是:

    1. (首选)将带有按钮的弹出窗口放在需要提交和验证的同一表单中。

    2. 将 a4j:jsFunction 放入 contentForm 并从弹出窗口中调用它,代码如下所示:

    .

    <h:form id="contentForm">
      .. other fields to be submitted ..
      <a4j:jsFunction name="executeContentFormAction" execute="@form" render="@form"
            action="#{...}"
            oncomplete="if ..."/>
    </h:form>
    
    ...
    
    <a4j:commandButton 
        id="saveContentChanges" 
        value="Speichern"
        onclick="executeContentFormAction(); return false;">
    

    【讨论】:

    • 谢谢安德烈!此外,我不得不用onbeforesubmit 隐藏弹出窗口,否则它也不起作用。但现在它运行良好。
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2021-05-02
    • 2021-10-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 2011-07-19
    • 1970-01-01
    相关资源
    最近更新 更多