ajax - ajax调用成功后数据表不更新

标签 ajax jsf jsf-2 primefaces

我有一个数据表。表的每一行都有一个 commandButton称为“删除”,它应该从模型和 View 中删除该行并就地执行更新。作为页脚,我还有一个 commandButton称为“删除每一行”。

最后一个按钮有效。我点击它,每一行都从模型中删除(即 ArrayList 包含元素变空)和 dataTablefooter facet在 View 中重新渲染(或更新)。

另一方面,当我单击其中一行上的按钮以将其删除时,它部分工作。相应的元素从模型中删除,但 View 没有更新。该行仍然存在于 dataTable 中和 footer facet没有改变。

我的 users.xhtml 中有以下代码.

<f:metadata>
    <f:viewParam name="id" value="#{users.id}" />
    <f:event type="preRenderView" listener="#{users.init}" />
</f:metadata>

...

<h:form id="usersForm">
    <p:outputPanel>    
        <p:dataTable id="userTable" value="#{users.user.friendList}" var="friend">
            <p:column>
                <h:outputText value="#{friend.name}" />
            </p:column>
            <p:column>
                <p:commandButton action="#{users.user.removeFriend(friend)}"
                    ajax="true"
                    update="userTable somethingElse" process="@this"
                    onerror="errorDialog.show();"
                    icon="ui-icon-delete"
                    title="delete user">
                </p:commandButton>
            </p:column>

            <f:facet id="somethingElse" name="footer">  
                    aye: ${users.user.xxx}
            </f:facet>
        </p:dataTable>

    </p:outputPanel>

    <p:commandButton action="#{users.user.removeAllFriends()}" ajax="true"
                update="userTable somethingElse"
                process="@this"
                icon="ui-icon-close"
                value="delete all friends?">
    </p:commandButton>


</h:form>

那么,您认为这里的问题是什么?

我使用的是 JSF 2.0 和 Primefaces 3.0

最佳答案

我从我们当前的 PF 3.0 页面之一中认识到了这个问题。如果您使用 update="@form" 它将起作用反而。我真的没有时间去调查真正的原因,以便我可以将其报告给 PF 人员,因为此问题并非在所有页面中都出现。即使在同一个表中,不同的按钮也会按预期工作。

试一试:

<p:commandButton update="@form" ... />

更新 : 仔细想想,可能跟process="@this"的存在有关.

关于ajax - ajax调用成功后数据表不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8803032/

相关文章:

java - 有没有类似<c :url> for JSF?

java - Primefaces,如何用另一个按钮折叠布局单元?

asp.net - AutoCompleteExtender - 滚动条导致结果关闭?

ruby-on-rails - 永远不要响应 xhrs 渲染布局

jquery - Ajax 调用返回 'undefined' - Companies House API

javascript - 为什么我的 $.ajax 显示 "preflight is invalid redirect error"?

tomcat - NoClassDefFoundError (Digester) 与 Tomcat 和 MyFaces

java - JSF h :inputText validation and f:ajax render

java - 我可以创建带注释的 Faces 应用程序监听器类吗?

java - 找不到 WebApplicationContext : no ContextLoaderListener registered?