【问题标题】:<p:dialog> stays open when validation has failed but corrected submission does not call action<p:dialog> 在验证失败但更正的提交不会调用操作时保持打开状态
【发布时间】:2014-08-12 19:46:01
【问题描述】:

由于以下密切相关的问题已有一年半的历史,我想我应该重新问这个问题。 Keep <p:dialog> open when validation has failed

我在&lt;p:dialog> 中打开了一个表单。如果正确输入并提交表单,一切都很好。如果用户提交无效信息,表单将保持打开状态,并且验证消息会按预期显示。但是,用户现在更正了表单并提交: 对话框关闭(很好,表单上不再有任何错误),但没有调用 commandButton 的 action 或 actionListener 方法。这是我仔细遵循链接问题的代码。

<h:form>
    ...
    <h:commandButton value="Add Event..." onclick="addEventDlg.show()" type="button"/> 
</h:form>

<p:dialog id="dlg" header="Add Event" widgetVar="addEventDlg" modal="true">
    <h:form id="addEventForm">
        <h:messages  style="color:red;margin:8px;" />
        <table>
            <tr>
                <td style="vertical-align:center"><h:outputLabel for="eventType" value="Event Type: " /></td>
                <td>
                    <h:selectOneListbox id="eventType" value="#{addEventBean.eventType}" required='true' requiredMessage="#{msgs.eventType}">
                        <f:selectItems value="#{addEventBean.eventTypes}" var="etype" itemLabel="#{etype.name}" itemValue="#{etype}"/>
                    </h:selectOneListbox>
                </td>
            </tr>
            <tr>
                <td><h:outputLabel for="title" value="Event Title: "/></td>
                <td><h:inputText id="title" value="#{addEventBean.title}" required="true" requiredMessage="#{msgs.eventTitle}"/></td>
            </tr>
            <tr>
                <td><h:outputLabel for="occuranceDate" value="Event Date: " /></td>
                <td><p:calendar id="occuranceDate" value="#{addEventBean.dateOfOccurance}" required="true" requiredMessage="#{msgs.eventOccuranceDate}" mode="popup" 
                                        showOn="button" showButtonPanel="true" pattern="yyyy/MM/dd" navigator="true" size="10"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <table>
                        <tr>
                            <td><p:commandButton value="Cancel" onclick="addEventDlg.hide()" type="button"/></td>
                            <td><p:commandButton value="Submit" action="#{addEventBean.addEventAction()}" type="submit"
                                                         update="addEventForm"
                                                         oncomplete="if( !args.validationFailed) addEventDlg.hide()"/>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </h:form>
</p:dialog>

我的 addEventBean 的 action 方法使用的是注入 bean 的控制器。

public String addEventAction() throws PersistenceException {
    Event e = ECPEvents.getInstance(eventType);
    e.setActualDate( dateOfOccurance);
    e.setName( title);

    return controller.insertEventAction( e);
}

上一篇文章使用了commandButton 的actionListener。我想用行动。我已经尝试了两种行为都没有改变。

我正在使用 mojarra 2.2、primefaces 3.5 和 tomcat 7。

有什么想法吗?提前谢谢你。

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    您是否尝试将表格放入带有 id (ed panelId) 的 p:panel 并尝试 进程="panelId"

    【讨论】:

    • 根据您的建议,我用 包围了外部表,并将 process="panelId" 添加到“提交”命令按钮。行为没有变化。
    猜你喜欢
    • 2012-12-28
    • 1970-01-01
    • 2015-03-09
    • 2023-04-03
    • 2013-06-14
    相关资源
    最近更新 更多