PrimeFaces对话框参考父级 [英] PrimeFaces dialog refer to parent

查看:80
本文介绍了PrimeFaces对话框参考父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xhtml页面,其中显示带有条目的数据表.我还具有一个用于插入新条目的按钮,该条目显示具有表单的对话框.插入形式在父.xhtml中用作<ui:include>,如下所示:

I have an xhtml page that display a Datatable with entries. I also have a button to insert a new entry, that displays a dialog that has a form. The insertion form is used as <ui:include> in the parent .xhtml as follows:

父文件

    <h:form id="mainForm">
        <p:commandButton process="@form" update=":dlgGrp" oncomplete="dlg.show()"/>

        <p:datatable id = "datatable"> 

            various columns
            .....
            .....
        </p:datatable>

    </h:form>

    <p:dialog widgetVar="dlg" >

        <h:panelGroup id="dlgGrp">
            <ui:include src="include.xhtml" />
        </h:panelGroup>
    </p:dialog>

</ui:composition>

对话框文件

<ui:composition xmlns . . .>

    <h:form id="subForm">

        various input fields
        ......  
        ......
        <p:commandButton process="@form" update=":mainForm" oncomplete="dlg.hide()"/>

    </h:form>

</ui:composition>

如文件中所示,如何通用地引用父组件.只需点击几下对话框中的提交"按钮,我就想更新主窗体并隐藏对话框.但是,这些组件在父域"中.

How can I refer generically to a parent component as show in the file. In a few words as soon as I hit the submit button in the dialog, I want to update the main form and hide the dialog. These components however are in the "parent field".

这可能应该通过辅助bean进行编程,因为我不想在子.xhtml中包含特定于父项的动作,因为我也可能希望将其用作独立的.xhtml.

This should probably be done programatically through the backing bean, since I do not want to include parent-specific actions in the child .xhtml, since I may aslo want to use it as a standalone .xhtml.

推荐答案

如果要通过backingBean中的方法更新mainForm.只需修改

If you want to update the mainForm through a method in the backingBean. Just modify

<p:commandButton process="@form" action="#{backingBean.method}" oncomplete="dlg.hide()"/>

,并在您的backingBean中执行以下操作(请参阅Primefaces展示):

and in your backingBean do the following (see Primefaces Showcase):

public void method() {
  // do something
  RequestContext context = RequestContext.getCurrentInstance();
  context.update(":mainForm");
}

您只需要检查您的mainForm是否已经在另一个 NamingContainer . 如果是这样,则需要相应地更改context.update(...).

You just need to check, if your mainForm is already in another NamingContainer. If so, you need to change the context.update(...) accordingly.

此外,如果要从备用Bean更新mainForm,我还建议根据处理的输入将对话框隐藏在backingBean中.如果例如有些数据无效,您不想隐藏对话框.当前,您的oncomplete操作无法做到这一点,该操作在收到服务器的响应后会自动执行.无论输入是否正确,对话框都会关闭.

Furthermore, if you want to update the mainForm from your backing bean, I would also recomment hiding the dialog in the backingBean, depending on the input processed. If e.g. some data is invalid, you don't want to hide the dialog. That cannot be done currently with your oncomplete action which is executed automatically after receiving the response from the server. The dialog would get close whether the input was correct or not.

因此添加到method():

if (everythingWentFine) {
  context.execute("dlg.hide();");
}

,然后从p:commandButton中删除oncomplete.

这篇关于PrimeFaces对话框参考父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆