【问题标题】:Primefaces two messages getting displayed instead of one for ajax blur eventPrimefaces 显示两条消息而不是一条用于 ajax 模糊事件
【发布时间】:2014-01-28 07:11:53
【问题描述】:

我有一行可编辑的数据表。我已经对必须在电子邮件字段模糊时显示错误消息的列之一实施了电子邮件验证。这工作正常。我有一个对话框,表单显示在同一页面中。验证也通过 on blur 事件实现到此表单。对话框验证消息显示在 blur 上,但同时主窗体也显示相同的验证消息。这不应该发生。

JSF 页面

<h:form id="lpcForm">

    <div id="content">

        <p:commandLink id="cmdLinkDelete" value="Delete"
            style="font-size:15px;padding-left:15px;" ajax="true"
            action="#{lpcBean.deleteRecords}" update=":lpcForm:lpcDataTable" />
        &nbsp;&nbsp;
        <p:commandLink id="cmdLinkAdd" value="Add" style="font-size:15px;"
            onclick="dlg.show()" />


        <p:messages id="lpcInfoMsg" for="lpcInfoMessages" showDetail="true"
            autoUpdate="true" closable="true" />
        <p:messages id="lpcErrMsg" showDetail="false" redisplay="false"
            styleClass="messagesClass" autoUpdate="true" closable="true" />

        <p:dataTable var="lpcData" id="lpcDataTable" widgetVar="lpcTable"
            value="#{lpcBean.lpcItems}" selection="#{lpcBean.selectedRows}"
            editable="true" scrollable="true" scrollWidth="80%"
            rowKey="#{lpcData.LPCID}" rendered="true"
            scrollHeight="75% important!" resizableColumns="true"
            tableStyle="table-layout:auto;width:100% important!; height:100% important!;padding-left:15px important!;"
            styleClass="datatable">

            <p:ajax event="rowEdit" listener="#{lpcBean.onEdit}" />
            <p:ajax event="rowEditCancel" listener="#{lpcBean.onCancel}" />
            <p:column selectionMode="multiple" style="width:15px" />


            <p:column headerText="LPC ID" style="width:20px"
                sortBy="#{lpcData.LPCID}">
                <h:outputText value="#{lpcData.LPCID}" />
            </p:column>



            <p:column headerText="Email" style="width:75px"
                sortBy="#{lpcData.email_Address}">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{lpcData.email_Address}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{lpcData.email_Address}" style="width:100%"
                            label="emailAddress" validatorMessage="Invalid Email Format">
                            <f:validateRegex
                                pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
                            <f:ajax event="blur" render=":lpcForm:lpcErrMsg" />
                        </p:inputText>
                    </f:facet>
                </p:cellEditor>
            </p:column>
                .
                .
                .
                .
                .

            <p:column style="width:10px">
                <p:rowEditor />
            </p:column>

        </p:dataTable>
        <p:blockUI block="lpcDataTable" trigger="cmdLinkDelete,cmdLinkAdd">  
    LOADING<br />
            <p:graphicImage value="/images/ajaxLoader.gif" />
        </p:blockUI>

    </div>
</h:form>


<p:dialog header="Add LPC" id="lpcDlg" widgetVar="dlg" rendered="true"
    appendToBody="true" resizable="true" modal="true">
    <h:form id="addLpc">

        <div align="center">

            <p:messages id="lpcDlgMsg"  showDetail="false"
                autoUpdate="true" closable="true" />
            <h:panelGrid id="addLpcForm" columns="2" appendToBody="true">

                <h:outputText value="LPC ID" />
                <p:inputText id="lpcId" value="#{lpcBean.lpcId}" required="true">
                    <f:ajax event="blur" render="lpcDlgMsg" />
                </p:inputText>
                .
                .
                .
                .
                .
            </h:panelGrid>
        </div>
        <div align="center">
            <p:commandButton id="submitButton" value="Submit" ajax="true"
                update=":lpcForm:lpcDataTable" action="#{lpcBean.formSubmit}"
                oncomplete="dlg.hide()" />
            <p:commandButton id="cancelButton" value="Cancel" ajax="true"
                onclick="dlg.hide()" />

        </div>
    </h:form>
</p:dialog>

ID 为 lpcErrMsg 的消息是我在电子邮件格式错误时在主页上模糊显示的消息。虽然我从未提到过,但此消息也会显示对话框字段验证此 id 将在对话框中呈现。

ID 为 lpcDlgMsg 的消息是我在带有 widgetvar dlg 的对话框中显示的消息。到目前为止,我已经实现了第一个模糊事件验证对话框中的必填字段。

【问题讨论】:

    标签: ajax jsf-2 primefaces


    【解决方案1】:

    一种方式&lt;p:messages ... globalOnly="false" /&gt;。其他方法是使用&lt;p:ajax ... listener="#{bean.renderMethod}" /&gt;&lt;p:messages ... rendered="#{bean.render}" /&gt;。 renderMethod 用于设置布尔渲染为真或假。

    【讨论】:

      【解决方案2】:

      我认为问题出在 autoUpdate="true" 上。只需根据要求更新消息 ID。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-04
        • 2017-11-25
        • 2023-04-04
        • 1970-01-01
        • 2022-08-22
        • 2021-02-20
        相关资源
        最近更新 更多