Set selected row from backup bean in datatable format

I use simple fonts that can be used with interactive strings, and I need to find a way to set the selected string from the bean.

There is my datatable definition:

<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> 

I tried the following approach, but to no avail. With bean support, I added a method:

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

And I added a test version to the XHTML page:

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

But nothig is changed to datatable, the choice has not changed ...

Please have any ideas how to solve this problem?

+6
source share
1 answer

Just set the value for selection="#{commonTableBean.selectedCablePathTblRow}" .

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

Source: https://habr.com/ru/post/918386/


All Articles