将模态 p:dialog 与另一个模态 p:dialog 叠加
Overlay modal p:dialog with another modal p:dialog
首先 - 我是 PrimeFaces 的新手,我想在另一个已经生成的对话框的顶部显示一个警告对话框。
查看代码看起来像(简化):
<p:dialog id="userDialog" header="User Account" widgetVar="userDialogView" modal="true" resizable="true" closable="fasle" showHeader="true" height="400" width="880px">
<h:form id="dataDialogForm">
...
</h:form>
</p:dialog>
<p:dialog id="warnDialog" header="Warning!" widgetVar="warnDialog" modal="true" appendTo="@(body)" height="300px" width="600px" resizable="false">
<h:outputText value="You are trying to delete. Do you want to proceed? Yes/No" />
</p:dialog>
和 warnDialog
的控制器来生成它
RequestContext.getCurrentInstance().execute("showDialog('warnDialog')");
warnDialog
生成正确,但显示在 userDialog
对话框下方,而不是在其顶部。
应用正在使用 PrimeFaces v6.0
org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 6.0
编辑:
经过测试的 confirmDialog
代码(简化)如下:
<p:dialog id="userDialog" header="User Account" widgetVar="userDialogView" modal="true" resizable="true" closable="fasle" showHeader="true" height="400" width="880px">
<h:form id="dataDialogForm">
...
<p:confirmDialog widgetVar="warnDialog" header="Confirmation" severity="warn" modal="true" resizable="false" position="top,left">
<f:facet name="message">
You are trying to delete. Do you want to proceed?
</f:facet>
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="pi pi-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="pi pi-times" />
</p:confirmDialog>
</h:form>
</p:dialog>
那个没有在 userDialog
上产生阻塞覆盖,也没有定位到视口的左上角而不是触发 confirmDialog
的元素。
我已经通过覆盖 PrimeFaces CSS 解决了我的问题,由于某种原因它没有正确处理覆盖对话框(与香草 jQuery UI 或 Bootstrap) 版本 5.x 和 6.x.
我的解决方案如下:
<p:dialog id="userDialog" header="User Account" widgetVar="userDialogView" modal="true" resizable="true" closable="fasle" showHeader="true" height="400" width="880px">
<h:form id="dataDialogForm">
...
</h:form>
</p:dialog>
<p:dialog id="warnDialog" header="Warning!" widgetVar="warnDialog" modal="true" height="300px" width="600px" resizable="false" styleClass="dialogWarn-fix">
<h:outputText value="You are trying to delete. Do you want to proceed? Yes/No" />
</p:dialog>
和CSS:
.dialogWarn-fix {
z-index: 9999 !important;
}
首先 - 我是 PrimeFaces 的新手,我想在另一个已经生成的对话框的顶部显示一个警告对话框。
查看代码看起来像(简化):
<p:dialog id="userDialog" header="User Account" widgetVar="userDialogView" modal="true" resizable="true" closable="fasle" showHeader="true" height="400" width="880px">
<h:form id="dataDialogForm">
...
</h:form>
</p:dialog>
<p:dialog id="warnDialog" header="Warning!" widgetVar="warnDialog" modal="true" appendTo="@(body)" height="300px" width="600px" resizable="false">
<h:outputText value="You are trying to delete. Do you want to proceed? Yes/No" />
</p:dialog>
和 warnDialog
的控制器来生成它
RequestContext.getCurrentInstance().execute("showDialog('warnDialog')");
warnDialog
生成正确,但显示在 userDialog
对话框下方,而不是在其顶部。
应用正在使用 PrimeFaces v6.0
org.primefaces.webapp.PostConstructApplicationEventListener.processEvent Running on PrimeFaces 6.0
编辑:
经过测试的 confirmDialog
代码(简化)如下:
<p:dialog id="userDialog" header="User Account" widgetVar="userDialogView" modal="true" resizable="true" closable="fasle" showHeader="true" height="400" width="880px">
<h:form id="dataDialogForm">
...
<p:confirmDialog widgetVar="warnDialog" header="Confirmation" severity="warn" modal="true" resizable="false" position="top,left">
<f:facet name="message">
You are trying to delete. Do you want to proceed?
</f:facet>
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="pi pi-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="pi pi-times" />
</p:confirmDialog>
</h:form>
</p:dialog>
那个没有在 userDialog
上产生阻塞覆盖,也没有定位到视口的左上角而不是触发 confirmDialog
的元素。
我已经通过覆盖 PrimeFaces CSS 解决了我的问题,由于某种原因它没有正确处理覆盖对话框(与香草 jQuery UI 或 Bootstrap) 版本 5.x 和 6.x.
我的解决方案如下:
<p:dialog id="userDialog" header="User Account" widgetVar="userDialogView" modal="true" resizable="true" closable="fasle" showHeader="true" height="400" width="880px">
<h:form id="dataDialogForm">
...
</h:form>
</p:dialog>
<p:dialog id="warnDialog" header="Warning!" widgetVar="warnDialog" modal="true" height="300px" width="600px" resizable="false" styleClass="dialogWarn-fix">
<h:outputText value="You are trying to delete. Do you want to proceed? Yes/No" />
</p:dialog>
和CSS:
.dialogWarn-fix {
z-index: 9999 !important;
}