JSF 2 + Primefaces - 更新不起作用

发布于 2024-11-01 16:22:19 字数 2697 浏览 1 评论 0原文

我已经搜索过,但即使实现了我找到的解决方案,我也无法使其正常工作。我在数据表中选择一行,然后单击删除按钮来删除所选对象,但该对象被删除,但数据表未更新。这是我的代码:

<h:form id="formPesquisa">  
            ...
            <h:panelGroup id="panelToRender" layout="block">
                <h:panelGroup id="panelDataTable" rendered="#{not empty bean.dataList}" layout="block">
                    <div id="dataTableRegion">
                        <p:panel id="panelBtnsUp" styleClass="cleanPanel">
                            <ui:include src="/templates/btnDataList.xhtml" />
                        </p:panel>
                        <h:panelGroup id="panelTableHolder" layout="block">
                            <p:dataTable id="dataTableBusca" value="#{bean.dataList}" var="entidade" 
                                rendered="#{not empty bean.dataList}" paginator="true" style="width:100%;"
                                selection="#{bean.entidadesSelecionadas}" onRowSelectUpdate="panelBtnsUp,panelBtnsDown,dataTableBusca"
                                onRowUnselectUpdate="panelBtnsUp,panelBtnsDown,dataTableBusca" rowUnselectListener="#{bean.rowUnselectListener}" selectionMode="multiple">
                                <p:column>
                                    <p:graphicImage url="/icons/checkbox_no.png" rendered="#{!bean.containsSelection(entidade)}" />
                                    <p:graphicImage url="/icons/checkbox_yes.png" rendered="#{bean.containsSelection(entidade)}" />
                                </p:column>
                                <ui:insert name="colunasPesquisa" />
                            </p:dataTable>
                        </h:panelGroup>
                        <p:panel id="panelBtnsDown" styleClass="cleanPanel">
                            <ui:include src="/templates/btnDataList.xhtml" />
                        </p:panel>
                    </div>
                </h:panelGroup>
            </h:panelGroup>
            ....
</h:form>

删除按钮位于包含的文件中:

<div style="margin:5px 0;">
    <p:commandButton value="#{msg['commons.excluir']}" image="delete" disabled="#{bean.disableDelete()}" action="#{bean.delete}" update="panelDataTable" />
    <p:commandButton value="#{msg['commons.editar']}" image="edit" disabled="#{bean.disableEdit()}" action="#{bean.prepareEdit}" ajax="false" />
</div>

我已经尝试过:

update =“dataTableBusca”
更新=“panelTableHolder”
更新=“formPesquisa:dataTableBusca”
update="formPesquisa:panelTableHolder"

我做错了什么???

感谢您的任何帮助。

I'lve already searched, but even implementing the solutions I've found, I was not able to get this working. I select a row in a datatable and click on delete button to delete the selected object, but the object gets deleted but the datatable is not updated. Here's my code:

<h:form id="formPesquisa">  
            ...
            <h:panelGroup id="panelToRender" layout="block">
                <h:panelGroup id="panelDataTable" rendered="#{not empty bean.dataList}" layout="block">
                    <div id="dataTableRegion">
                        <p:panel id="panelBtnsUp" styleClass="cleanPanel">
                            <ui:include src="/templates/btnDataList.xhtml" />
                        </p:panel>
                        <h:panelGroup id="panelTableHolder" layout="block">
                            <p:dataTable id="dataTableBusca" value="#{bean.dataList}" var="entidade" 
                                rendered="#{not empty bean.dataList}" paginator="true" style="width:100%;"
                                selection="#{bean.entidadesSelecionadas}" onRowSelectUpdate="panelBtnsUp,panelBtnsDown,dataTableBusca"
                                onRowUnselectUpdate="panelBtnsUp,panelBtnsDown,dataTableBusca" rowUnselectListener="#{bean.rowUnselectListener}" selectionMode="multiple">
                                <p:column>
                                    <p:graphicImage url="/icons/checkbox_no.png" rendered="#{!bean.containsSelection(entidade)}" />
                                    <p:graphicImage url="/icons/checkbox_yes.png" rendered="#{bean.containsSelection(entidade)}" />
                                </p:column>
                                <ui:insert name="colunasPesquisa" />
                            </p:dataTable>
                        </h:panelGroup>
                        <p:panel id="panelBtnsDown" styleClass="cleanPanel">
                            <ui:include src="/templates/btnDataList.xhtml" />
                        </p:panel>
                    </div>
                </h:panelGroup>
            </h:panelGroup>
            ....
</h:form>

And the Delete Button is in the included file:

<div style="margin:5px 0;">
    <p:commandButton value="#{msg['commons.excluir']}" image="delete" disabled="#{bean.disableDelete()}" action="#{bean.delete}" update="panelDataTable" />
    <p:commandButton value="#{msg['commons.editar']}" image="edit" disabled="#{bean.disableEdit()}" action="#{bean.prepareEdit}" ajax="false" />
</div>

I already tried:

update="dataTableBusca"
update="panelTableHolder"
update="formPesquisa:dataTableBusca"
update="formPesquisa:panelTableHolder"

What am I doing wrong???

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧瑾黎汐 2024-11-08 16:22:19

仅当您的按钮和更新的元素是同级元素时,前两种方法才有效。

对于第三种和第四种方法,您必须遍历所有包含元素才能获得正确的 id。 panelTableHolder 位于另外两个 h:panelGroup (panelToRender、panelDataTable)和一个 div (dataTableRegion) 内。

此外,为了确保从最高级别开始,请在表单 ID 之前添加 : 。

试试这个:

update=":formPesquisa:panelToRender:panelDataTable:dataTableRegion:panelTableHolder"

如果这是你的 panelTableHolder 的正确路径,你可以检查渲染的 html。

The first two approaches will only work if your button and the updated elements are siblings.

For the third and the fourth approach you have to traverse all containing elements in order to get the right id. You panelTableHolder is inside two other h:panelGroup (panelToRender, panelDataTable) and a div (dataTableRegion).

Furthermore to make sure that you start from highest level, prepend a : before the form id.

Try this:

update=":formPesquisa:panelToRender:panelDataTable:dataTableRegion:panelTableHolder"

You could check in the rendered html if this is the correct path for your panelTableHolder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文