confirmDialog appears but disappears immediately

随声附和 提交于 2020-01-06 06:55:58

问题


I have read similar questions on SA and the Primefaces forum but it did not help. Here is the xhtml:

<h:form id="form2" prependId="false">
    <p:remoteCommand name="sendNameClicked" actionListener="#{reportBean.passName}"/>
    <p:remoteCommand name="updateDialog" update=":form3:dialogBox"/>

    <p:commandButton style="display: none" id="displayDialog" type="button" onclick="cd.show(); return false;"/>
</h:form>
<h:form id="form3">
    <p:confirmDialog id ="dialogBox" message= "#{reportBean.getClickedAuthorLaius()}"
                     header="#{reportBean.nameClicked}#{reportBean.authorClicked.mostRecentAffiliation}"
                     widgetVar="cd"
                     severity="info"
                     >
        <h:outputText styleClass="ui-widget"  value="" escape="false" />
        <p:commandButton value="Draw the ring of #{reportBean.obtainFullName()}?" actionListener ="#{controllerBean.prepareNewSearch()}" action ="index?faces-redirect=true" oncomplete="cd.hide();"/>
        <p:commandButton value="No, stay on this page" onclick="cd.hide();" type="button" />
    </p:confirmDialog>
</h:form>

Any help very much appreciated!


回答1:


The onclick is fired before the form submit request is sent. The update is performed after form submit response is arrived. So, the confirm dialog is updated after it's been opened and thus get its default appearance again.

You need to open it after the update. Use the oncomplete attribute instead of onclick.

<p:commandButton ... oncomplete="cd.show()"/>


来源:https://stackoverflow.com/questions/13100749/confirmdialog-appears-but-disappears-immediately

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!