【问题标题】:Validation errors in dialog not updating after failed submit in JSF在 JSF 中提交失败后对话框中的验证错误未更新
【发布时间】:2014-07-23 00:41:01
【问题描述】:

所以我点击了一个打开对话框的按钮。在此对话框中,我想在表单中填写信息并提交并保存。需要一些 inputTexts 才能提交。所以我使用 required="true" 属性。它会停止提交,但不会使用所有内容的红色轮廓更新该字段。现在,如果我点击取消并再次打开对话框,它将以红色轮廓显示验证失败的字段!

我想我可以通过在尝试提交表单时手动更新对话框来解决这个问题。这只会导致对话框关闭,而不是保持打开状态并刷新对话框以显示验证失败。

这是对话框,当我点击保存按钮时是我提交表单时

<h:form>

    <p:dialog header="#{headerValue}" widgetVar="#{uniqueId}_editDialog"
        modal="false" showEffect="fade" styleClass="dialogGrid"
        dynamic="true" draggable="true" resizable="false">
        <p:outputPanel style="text-align:center;" layout="block">
         <p:messages autoUpdate="true"/>
            <ui:insert name="editContent">
      Edit Content Here. Use 'selectedModel.whatever'
    </ui:insert>
            <p:panelGrid columns="3" styleClass="buttonGrid">
                <ui:insert name="saveButton">
                    <p:commandButton iconPos="left" value="#{msg.save}"
                        rendered="#{'VIEW' != selectedModel.viewState}"
                        process="@widgetVar(#{uniqueId}_editDialog)"
                        action="#{adapterInjector.add(modelList, selectedModel)}"
                        update="@widgetVar(#{uniqueId}_itemsDataList) @widgetVar(#{uniqueId}_addButton) @widgetVar(#{uniqueId}_editDialog)"
                        oncomplete="if(!args.validationFailed) PF('#{uniqueId}_editDialog').hide()"
                        partialSubmit="true" validateClient="true">
                    </p:commandButton>
                </ui:insert>

                <p:commandButton iconPos="right" value="#{msg.cancel}"
                    process="@this" oncomplete="PF('#{uniqueId}_editDialog').hide()"
                    resetValues="true" partialSubmit="true">
                </p:commandButton>
            </p:panelGrid>
        </p:outputPanel>
    </p:dialog>
</h:form>

这是一个插入的组件,具有必需的属性

    <p:selectOneMenu id="licenseCert"
                    value="#{selectedModel.selectedLicenseCert}" filter="true"
                    required="true">
                    <f:selectItem itemLabel="#{msg.selectOne}" itemValue=""
                        noSelectionOption="true" />
                    <f:selectItems value="#{licCert.allLicenseCertMap.entrySet()}"
                        var="entry" itemValue="#{entry.key}" itemLabel="#{entry.value}" />
                </p:selectOneMenu>
            </p:column>

【问题讨论】:

  • 不确定这是否能解决问题。为了获得最佳实践,您应该:1) 在对话框中移动 &lt;h:form&gt; 和 2) 在保存按钮中移动 process &lt;h:form&gt;
  • 成功了,非常感谢
  • 我已将其添加为未来用户的常规答案。

标签: ajax validation jsf jakarta-ee primefaces


【解决方案1】:

事实证明这解决了问题。

为了获得最佳实践,您应该:

  1. 在对话框内移动&lt;h:form&gt;
  2. 在保存按钮中处理移动的&lt;h:form&gt;

【讨论】:

  • 第二条指令是什么意思?非常感谢
  • @unpix:我通常建议不要在表单之外提交/处理数据,所以#2,我的意思是你应该将&lt;h:form&gt;...&lt;p:commandButton value="Save" process="@widgetVar(#{uniqueId}_editDialog)"更改为&lt;h:form id="#{uniqueId}_Form"&gt;... &lt;p:commandButton value="Save" process="#{uniqueId}_Form"或类似的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-30
  • 2015-01-29
  • 2010-12-27
  • 2010-10-19
  • 1970-01-01
相关资源
最近更新 更多