使用AJAX更新JSF/Primefaces数据表中的单行 [英] Update single row in JSF / Primefaces datatable using AJAX
问题描述
使用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行.为了更新当前行,您需要将行索引作为参数传递.在<p:dataTable>
上设置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屋!