2012-06-18 40 views
6

我正在使用可點擊行數據的primefaces,並且我需要找到如何從支持bean中設置選定行的方法。在primefaces數據表中設置支持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我已經加入方法:

public void test(){ 
    DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:cablePathTable"); 
    dataTable.setRowIndex(2); 
} 

而且我已經加入測試butoon到XHTML頁面:

<p:commandButton process="@this" update=":form:cablePathTable" value="set2row" action="commonTableBean.test"/> 

但理智最多改變的數據表,選擇沒有改變...

請有任何想法如何解決這個問題?

回答

7

只需將值設置爲selection="#{commonTableBean.selectedCablePathTblRow}"

public void test(){ 
    selectedCablePathTblRow = cablepath; 
} 
+0

D'Oh!這很容易!非常感謝你! –

+0

不客氣。既然你是新來者,請不要忘記標記接受的答案,只要它有助於解決問題。另請參閱[如何接受答案的工作?](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) – BalusC

+1

是否有可能做到這一點時該頁面顯示爲?沒有按下一個命令按鈕? – roel

相關問題