使用 AJAX 更新 JSF/Primefaces 数据表中的单行 [英] Update single row in JSF / Primefaces datatable using AJAX

查看:27
本文介绍了使用 AJAX 更新 JSF/Primefaces 数据表中的单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用 AJAX 时更新 p:datatable 中的单行?

How could I update a single row in a p:datatable when using AJAX?

我不想更新整个数据表,因为它有很多行并且需要一些时间..

I don't want to update the whole datatable because it has a lot of rows and it's going to take some time..

我的布局:

<h:form id="visitForm">
        <p:dataTable id="visitTable" var="visit" value="#{visitBean.findAllVisits()}">

            <p:column headerText="${msgs['email']}"
                <h:outputText value="#{visit.contactDetail.email}"/>
            </p:column>

            <p:column headerText="${msgs['clearance']}" id="clearance">
                <p:commandButton value="${msgs['clearance.ok']}"  actionListener="#{visitBean.makeClearanceNotOk(visit)}"/>
            </p:column>
        </p:dataTable>
    </h:form>

我尝试了一些诸如 update = "clearance" 之类的方法,但似乎不起作用.

I've tried out some things like update = "clearance" etc but it doesn't seem to work.

我使用的是 JSF 2.1 和 Primefaces 5.2

I'm using JSF 2.1 and Primefaces 5.2

推荐答案

您可以使用 @row(n) 搜索表达式,它就是这样做的 - 它更新表中的第 n 行.为了更新当前行,您需要将行索引作为参数传递.在 上设置 rowIndexVar="rowIdx" 属性,然后:

You can use @row(n) search expression which does just that - it updates the nth row in a table. In order to update the current row, you need to pass row index as an argument. Set rowIndexVar="rowIdx" attribute on <p:dataTable> and then:

<p:commandButton ... update="@form:visitTable:@row(#{rowIdx})" />

这篇关于使用 AJAX 更新 JSF/Primefaces 数据表中的单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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