JSF f:ajax 无法在上下文中定位组件

发布于 2024-12-08 01:09:37 字数 2874 浏览 0 评论 0 原文

我正在尝试从数据表内的图形图像更新一个数据表。我尝试了很多 f:ajax 渲染值的组合但没有成功,现在我使用 PrimeFaces 的 p:component 函数,但我之前遇到了同样的错误。我在浏览器中收到此错误:

f:ajax 包含未知 ID 'j_idt690:painelTabelaAPDespesa' - 无法在组件 j_idt735 的上下文中找到它

f:ajax 包含未知 id 'j_idt690:painelTabelaAPDespesa' - 无法在我用来刷新的代码

<f:ajax event="click" render="#{p:component('painelTabelaAPDespesa')}"
                    listener="#{itensAPDespesa.removerItem(item)}" />

:如何看到此 f:ajax 位于数据表内的图形图像内。

<h:panelGroup id="painelTabelaAPDespesa">
        <p:dataTable id="tabelaAPDespesa" value="#{itensAPDespesa.itens}"
            var="item">
            <p:column>
                #{itensAPDespesa.itens.indexOf(item)+1}
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Número" />
                </f:facet>
                <hrgi:editableText style="width:33%"
                    value="#{item.numeroDocumento}" />
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Vencimento" />
                </f:facet>
                <hrgi:editableDate style="width:33%" value="#{item.dataVencimento}" />
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Valor" />
                </f:facet>
                <hrgi:editableCurrency style="width:33%" value="#{item.valor}">
                    <f:ajax render="@form" event="blur"
                        listener="#{itensAPDespesa.adicionarItem(item)}"
                        onevent="mudarFocoParaCampoInexistente(this.id)" />
                </hrgi:editableCurrency>
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Remover" />
                </f:facet>
                <h:graphicImage library="img" name="default_trash.png"
                    style="cursor:pointer;">
                    <f:ajax event="click" render="#{p:component('painelTabelaAPDespesa')}"
                        listener="#{itensAPDespesa.removerItem(item)}" />
                </h:graphicImage>
            </p:column>
        </p:dataTable>
        <h:outputLabel
            value="Total: #{modeloPopupRegistroDespesa.valorTotal}">
            <f:convertNumber type="currency" currencyCode="BRL"
                currencySymbol="R$" maxFractionDigits="2" minFractionDigits="2" />
        </h:outputLabel>
    </h:panelGroup>

可能这是因为它不知道它位于我想要渲染的组件内部,所以我如何刷新这个组件(在本例中是 dataTable 的父组件)?

I'm trying update one dataTable from a graphicImage inside the dataTable. I tried a lot of combination of f:ajax render value but without success, now I'm using p:component function of PrimeFaces, but I get the same error before. I receive this error in browser:

f:ajax contains an unknown id 'j_idt690:painelTabelaAPDespesa' - cannot locate it in the context of the component j_idt735

the code I use to refresh:

<f:ajax event="click" render="#{p:component('painelTabelaAPDespesa')}"
                    listener="#{itensAPDespesa.removerItem(item)}" />

how you can see this f:ajax is inside a graphicImage that's inside a data table.

<h:panelGroup id="painelTabelaAPDespesa">
        <p:dataTable id="tabelaAPDespesa" value="#{itensAPDespesa.itens}"
            var="item">
            <p:column>
                #{itensAPDespesa.itens.indexOf(item)+1}
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Número" />
                </f:facet>
                <hrgi:editableText style="width:33%"
                    value="#{item.numeroDocumento}" />
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Vencimento" />
                </f:facet>
                <hrgi:editableDate style="width:33%" value="#{item.dataVencimento}" />
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Valor" />
                </f:facet>
                <hrgi:editableCurrency style="width:33%" value="#{item.valor}">
                    <f:ajax render="@form" event="blur"
                        listener="#{itensAPDespesa.adicionarItem(item)}"
                        onevent="mudarFocoParaCampoInexistente(this.id)" />
                </hrgi:editableCurrency>
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Remover" />
                </f:facet>
                <h:graphicImage library="img" name="default_trash.png"
                    style="cursor:pointer;">
                    <f:ajax event="click" render="#{p:component('painelTabelaAPDespesa')}"
                        listener="#{itensAPDespesa.removerItem(item)}" />
                </h:graphicImage>
            </p:column>
        </p:dataTable>
        <h:outputLabel
            value="Total: #{modeloPopupRegistroDespesa.valorTotal}">
            <f:convertNumber type="currency" currencyCode="BRL"
                currencySymbol="R$" maxFractionDigits="2" minFractionDigits="2" />
        </h:outputLabel>
    </h:panelGroup>

Probably this is caused because it don't know it is inside the component I want render, so how can I refresh this component (in this case the parent of dataTable)??

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

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

发布评论

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

评论(2

青瓷清茶倾城歌 2024-12-15 01:09:37

您可以将组件绑定到视图并引用其 render 中改为“nofollow">UIComponent#getClientId()

<h:panelGroup id="painelTabelaAPDespesa" binding="#{painel}">
    <p:dataTable id="tabelaAPDespesa" value="#{itensAPDespesa.itens}" var="item">
        ...
        <f:ajax render=":#{painel.clientId}" ... />
        ...
    </p:dataTable>
</h:panelGroup>

You could bind the component to the view and reference its UIComponent#getClientId() in the render instead:

<h:panelGroup id="painelTabelaAPDespesa" binding="#{painel}">
    <p:dataTable id="tabelaAPDespesa" value="#{itensAPDespesa.itens}" var="item">
        ...
        <f:ajax render=":#{painel.clientId}" ... />
        ...
    </p:dataTable>
</h:panelGroup>
彩扇题诗 2024-12-15 01:09:37

PrimeFaces 组件具有更智能的上下文无关组件定位算法。你可以尝试用它来代替。

<h:panelGroup id="painelTabelaAPDespesa">
    <p:dataTable id="tabelaAPDespesa" value="#{itensAPDespesa.itens}" var="item">
        ...
        <p:ajax update="painelTabelaAPDespesa" ... />
        ...
    </p:dataTable>
</h:panelGroup>

The PrimeFaces <p:ajax> component has a bit more smart context-independent component locating algorithm. You could try using it instead.

<h:panelGroup id="painelTabelaAPDespesa">
    <p:dataTable id="tabelaAPDespesa" value="#{itensAPDespesa.itens}" var="item">
        ...
        <p:ajax update="painelTabelaAPDespesa" ... />
        ...
    </p:dataTable>
</h:panelGroup>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文