在Primefaces数据表中设置从支持Bean选择的行 [英] Set selected row from backing bean in primefaces datatable
本文介绍了在Primefaces数据表中设置从支持Bean选择的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将primefaces数据表与可点击的行一起使用,我需要找到一种方法来设置从支持bean中选择的行.
I am using primefaces datatable with clickable rows and I need to find way how to set selected row from backing bean.
有我的数据表定义:
<p:dataTable id="cablePathTable" var="cablePath" value="#{commonTableBean.cableLazyModel}" rows="100"
selectionMode="single" selection="#{commonTableBean.selectedCablePathTblRow}"
rowIndexVar="rowIndex" widgetVar="datatableVar"
emptyMessage="---">
<p:ajax event="rowSelect" process="@this" update=":form:portFieldset" />
<p:column headerText="No">
<h:outputText value="#{cablePath.column1}" />
</p:column>
<p:column headerText="Port A">
<h:outputText value="#{cablePath.column4}" />
</p:column>
<p:column headerText="Port B">
<h:outputText value="#{cablePath.column5}" />
</p:column>
我尝试了以下方法,但没有成功. 在支持bean中,我添加了方法:
I have tried following approach, but with no success. In backing bean I have added method:
public void test(){
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:cablePathTable");
dataTable.setRowIndex(2);
}
并且我已将测试按钮添加到XHTML页面:
And I have added test butoon to the XHTML page:
<p:commandButton process="@this" update=":form:cablePathTable" value="set2row" action="commonTableBean.test"/>
但是数据表上的nothig已更改,选择未更改...
But nothig is changed on the datatable, selection didn't change...
请问如何解决这个问题?
Please any ideas how to solve this problem?
推荐答案
只需在selection="#{commonTableBean.selectedCablePathTblRow}"
后面设置值即可.
Just set the value behind selection="#{commonTableBean.selectedCablePathTblRow}"
.
public void test(){
selectedCablePathTblRow = cablepath;
}
这篇关于在Primefaces数据表中设置从支持Bean选择的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文