Generics Primefaces-更新模式对话框

Generics Primefaces-更新模式对话框,generics,primefaces,modal-dialog,Generics,Primefaces,Modal Dialog,我在使用从外部xhtml文件加载的primeface模式对话框时遇到问题 我的意图是:按下按钮应该调用带有参数“T”的方法“setType”(调用此方法的原因是根据类型重用对话框)。在此方法中,dialog.xhtml中的DualList将重新加载正确的和类型相关的数据。之后,将显示对话框 我目前的代码是: <p:commandButton value="#{bean.value}" id="button" type="button" icon="ui-icon-newwin" oncli

我在使用从外部xhtml文件加载的primeface模式对话框时遇到问题

我的意图是:按下按钮应该调用带有参数“T”的方法“setType”(调用此方法的原因是根据类型重用对话框)。在此方法中,dialog.xhtml中的DualList将重新加载正确的和类型相关的数据。之后,将显示对话框

我目前的代码是:

<p:commandButton
value="#{bean.value}"
id="button" type="button" icon="ui-icon-newwin"
onclick="varDialog.show()" style="width: 70px;">

<p:ajax listener="#{bean.setType('T'.charAt(0))}"
    update="dialog" />

<p:dialog id="dialog"
    widgetVar="varDialog"
    header="Dialog Header"
    resizable="false" modal="true" dynamic="true" width="900"
    appendToBody="true">
    <ui:include src="dialog.xhtml" />
</p:dialog>
</p:commandButton>

问题是对话框显示后会立即消失(我猜这是因为“update=”dialog“)。但忽略此代码将在没有可见数据的对话框中结束



所以我的问题是:如何实现加载具有特定类型数据的通用外部对话框?

在这种情况下为什么使用AJAX?我将采取行动:

<p:commandButton
    value="#{bean.value}"
    id="button"
    type="button"
    icon="ui-icon-newwin"
    style="width: 70px;"
    action="#{bean.prepareDialog}">
PF中有一个bug,它要求你在一篇文章的条件if部分中包含一个动态对话,否则它只会加载并忽略动态对话。这可能适用于您的场景,但我无法仅通过查看示例代码来评估它

<c:if test="#{bean.condition != null}">
    <ui:include src="dialog.xhtml"/>
</c:if>

我自己在读这篇文章时找到了答案:

我犯的第一个错误是嵌套的(一个在main.xhtml中,一个在included dialog.xhtml中)。因此,在线程的帮助下,我将代码更改为:

<h:form>
<p:commandButton
    value="#{bean.value}"
    id="supplierButton" icon="ui-icon-newwin"
    actionListener="#{bean.prepareDialog('T'.charAt(0))}"
    oncomplete="varDialog.show()"
    update=":tabView:dialog"
    immediate="true" style="width: 70px;">
</p:commandButton>
</h:form>

<p:dialog id="dialog"
    widgetVar="varDialog"
    header="Dialog title"
    resizable="false" modal="true" dynamic="true" width="900"
    appendToBody="true">
    <ui:include src="dialog.xhtml" />
</p:dialog>

这很有魅力

<h:form>
<p:commandButton
    value="#{bean.value}"
    id="supplierButton" icon="ui-icon-newwin"
    actionListener="#{bean.prepareDialog('T'.charAt(0))}"
    oncomplete="varDialog.show()"
    update=":tabView:dialog"
    immediate="true" style="width: 70px;">
</p:commandButton>
</h:form>

<p:dialog id="dialog"
    widgetVar="varDialog"
    header="Dialog title"
    resizable="false" modal="true" dynamic="true" width="900"
    appendToBody="true">
    <ui:include src="dialog.xhtml" />
</p:dialog>