【问题标题】:Check which form has an error检查哪个表单有错误
【发布时间】:2012-07-19 19:28:10
【问题描述】:

我有一个模式窗口,我只想在页面上的多个表单之一出现错误时启动它。有没有办法使用 el 来识别特定表单是否有错误?

示例伪代码:

<h:form id="form1">

</h:form>

<h:form id="form2">

</h:form>

<a4j:rendered="#{form1.hasErrors()}">
    ... modal here ... 
</a4j:rendered>

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    如果您在 ajax 请求中有 execute="@form",那么您可以将 UIForm#isSubmitted()FacesContext#isValidationFailed() 结合使用。

    <h:form binding="#{form1}">
    
    </h:form>
    
    <h:form binding="#{form2}">
    
    </h:form>
    
    <a4j:xxx rendered="#{form1.submitted and facesContext.validationFailed}">
        Validation of form1 has failed.
    </a4j:xxx>
    
    <a4j:xxx rendered="#{form2.submitted and facesContext.validationFailed}">
        Validation of form2 has failed.
    </a4j:xxx>
    

    【讨论】:

    • 有没有办法通过标准的 表单提交来完成同样的任务?
    • 当然它也适用于同步请求。我并不是要暗示它只适用于 ajax 请求,但只有在表单本身也包含在 execute 中时,它才会在 ajax 请求的情况下有效。例如,如果您在 execute 中仅包含特定的输入字段(这可以通过例如根据 #{param} 确定按下的按钮来解决),它将不起作用。我只是假设您使用的是 ajax,因为您有一个 a4j 组件。
    猜你喜欢
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多