【问题标题】:Primefaces close modal without hide dialogPrimefaces关闭模态而不隐藏对话框
【发布时间】:2019-03-09 02:19:11
【问题描述】:

我在 JavaEE 8 上使用 primefaces 6.2。
我有一个带有命令按钮的基本对话框,在该对话框上创建了一个模式。(抱歉英语不好!)
我想在不关闭基本对话框的情况下关闭模式。
如何解决这个问题?


<p:dialog header="Basic Dialog" id="user-management" widgetVar="user-management" width="700px" height="300px" resizable="false">
        <p:toolbar>
            <f:facet name="left">
                <p:commandButton type="button" title="Add" icon="ui-icon-plus" onclick="PF('userDialog').show();"/>
            </f:facet>
        </p:toolbar>
        <p:spacer/>
        <p:dataTable value="#{userGroupBean.userSet}" var="user">
            // Show user information
        </p:dataTable>
    </p:dialog>

    <p:dialog header="User"     
              widgetVar="userDialog"
              closeOnEscape="true"
              resizable="true"
              modal="true"
              showEffect="fade"
              hideEffect="fade"
              height="auto"
              width="auto">
        <h:panelGrid columns="2">
          // Some inputs ...
        </h:panelGrid>
        <p:spacer/>
        <div class="dialog-footer">
            <p:commandButton value="Save"
                             oncomplete="PF('userDialog').hide();"
                             process="@form"
                             update="user-management"
                             action="#{userGroupBean.save}"/>
        </div>
    </p:dialog>     

【问题讨论】:

    标签: primefaces jsf-2 jsf-2.2


    【解决方案1】:

    基本对话框不是“关闭”的,它是通过update="user-management" 更新的,因此从服务器返回的 html 被放入 html dom 中,对话框处于默认状态:关闭。您有多种选择:

    • 不要更新对话框,而是通过添加例如更新它的内容(我的首选解决方案)里面有一个面板并更新它
    • 在 bean 中设置标志并使用 visible="#{mybean.dialogIsVisibleFlag}"
    • 在 ajax 调用的 oncomplete 中做一个PF('user-management').show()

    【讨论】:

    • 谢谢你的意思,已修复。
    猜你喜欢
    • 2022-11-03
    • 2022-01-05
    • 1970-01-01
    • 2012-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 2014-10-08
    相关资源
    最近更新 更多