【发布时间】:2016-09-09 13:19:36
【问题描述】:
一旦用户单击“更新”命令按钮,我需要您的帮助来更新数据表中的特定行值,而不是具有特定值的整个数据表。
数据表如下所示:
<p:dataTable value="#{testController.employeeList}" id="Employee" var="emp"
rowIndexVar="rowIndex"
selection="#{testController.selectedEmployees}" rowKey="#{emp.id}"
rowSelectMode="checkbox">
<p:columnGroup type="header">
<p:row>
<p:column/>
<p:column headerText="ID"/>
<p:column headerText="Name"/>
<p:column headerText="Remarks"/>
<p:column headerText="Update"/>
</p:row>
</p:columnGroup>
<p:column selectionMode="multiple"/>
<p:column headerText="ID">
<h:outputText value="#{emp.id}"/>
</p:column>
<p:column headerText="Name">
<h:outputText value="#{emp.name}" id="name"/>
</p:column>
<p:column headerText="Remarks">
<h:inputText id="inputT1" value="#{emp.remarks}"/>
</p:column>
<p:column headerText="Update">
<p:commandButton id="updateCmd" title="Update"
actionListener="#{testController.updateRecord}">
</p:commandButton>
</p:column>
</p:dataTable>
这里是方法代码:
public void updateRecord(ActionEvent actionEvent) {
FacesContext context = FacesContext.getCurrentInstance();
Employee selectedRecord = context.getApplication().evaluateExpressionGet(context, "#{emp}", Employee.class);
selectedRecord.setRemarks("Updated");
String name1=selectedRecord.getRemarks();
System.out.println("name1"+name1);
// I need to update the row only or the cell with the remarks Updated by
//without refreshing full dataTable
//RequestContext.getCurrentInstance().update("request:Employee");
//Above line will update the full table, I need only the row or the cell value
}
【问题讨论】:
-
@Kukeltje 它没有显示答案
-
在您的xhtml页面中,我可以看到只有一个输入字段备注。但是在您的更新方法中,您正在更新名称。你想达到什么目的?
-
@Unknown 我已经修改了代码,我只想更新该行或单元格的备注“刷新”。
-
@Unknown 感谢您的解决方案...我会在明天之前尝试一下,我会及时通知您
标签: ajax jsf jsf-2 primefaces datatable