【问题标题】:Primefaces 8.0 JSF not updating table [duplicate]Primefaces 8.0 JSF不更新表[重复]
【发布时间】:2021-02-24 01:06:16
【问题描述】:

当我单击 addTagButton 时,一切正常。它更新所有三个组件:标签、tagId 和 addTagButton。

    <p:commandButton id="addTagButton" icon="ui-icon-plus"
            action="#{searchBean.addTag}" 
            update="tags, tagId, addTagButton"
            disabled="#{searchBean.tagChoices.size() == 0}">
    </p:commandButton>
    

这是表格组件:

    <h:dataTable id="tags" var="tag" value="#{searchBean.tags}">
        <h:column>
            <div style="text-align:right;">
                <h:outputLabel value="#{tag.typeName}:"/>
            </div>
        </h:column>
        <h:column>
            <p:inputText id="tag" size="25" value="#{tag.typeValue}"
                disabled="#{searchBean.searchForParent}"/>
        </h:column>
        <h:column>
            <p:commandButton id="delTagButton" icon="pi pi-trash" 
                action="#{searchBean.deleteTag}"
                update=":contentForm:tagId, :contentForm:addTagButton, tags">
                <f:setPropertyActionListener 
                    target="#{searchBean.tagId}" 
                    value="#{tag.typeName}" />
            </p:commandButton>
        </h:column>
    </h:dataTable>

当我单击标签表中每一行上的 delTagButton 时,操作正常,:contentForm:tagId 和 :contentForm:addTagButton 更新正常。但是点击命令按钮所在的标签表不会更新。

当删除一行时,更改必须反映在不起作用的标签表中。

现在,如果我将 h:dataTable 更改为 p:dataTable 或任何其他 primefaces 组件,它就可以工作。我正在尝试使其与 h:dataTable 一起使用。

Primefaces 8.0,JSF 2.5

【问题讨论】:

    标签: jsf primefaces ajax-update


    【解决方案1】:

    看看这个简单的例子:

    <h:form id="form">
        <h:panelGroup id="wrapper" layout="block">
            <h:dataTable id="table" border="1" value="#{testBean.list}" var="person">
                <h:column>#{person.name}</h:column>
                <h:column>#{person.surname}</h:column>
                <h:column>
                    <p:commandButton id="delTagButton" icon="pi pi-trash" 
                        action="#{testBean.remove(person)}" update="table">
                    </p:commandButton>
                </h:column>
            </h:dataTable>
        </h:panelGroup>
    </h:form>
    

    要真正了解正在更新的内容,请查看浏览器控制台。

    如果您尝试update="table",则不会发生任何事情(就像在您的代码中一样)。如果您尝试更新表的父级(通常是这种情况),您将收到错误错误:

    SEVERE: Error Rendering View[/example.xhtml]
    org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "wrapper" referenced from "form:table:0:delTagButton".
    at org.primefaces.expression.SearchExpressionFacade.cannotFindComponent(SearchExpressionFacade.java:677)
    

    所以我们可以尝试使用“年长”的父母并意识到update="@form" 有效!好的,所以我们想帮助找到id="table\wrapper" 组件。让我们试试 clientId update="form:table"。就像update="table" 一样,什么也没有发生。并且 PF 没有错误(因此可以找到元素 )。这可能意味着h:dataTable 不能从内部正确重新渲染(但我不想扔石头:-))。这通常是一种情况,例如JSF 3rd 方组件库中的弹出窗口。

    在这个特定的示例中,我会说,您必须更新 form:wrapper(添加 form: 有效)或仅更新 @form 才能使其正常工作。使用您的代码将是相同的。尝试更新一些父表或整个表单。


    以上所有都在 JSF 2.2 中进行了测试,最后一个 RF、一个旧的 PF 和 OmniFaces。但我认为新版本也是如此。

    顺便说一句。我不知道有 JSF 2.5 :-)

    【讨论】:

    • OK 将尝试添加包装器并重新测试代码。 2.5 是一个错字,将修复它:)
    猜你喜欢
    • 2021-05-11
    • 2021-01-25
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    相关资源
    最近更新 更多