0
votes

I try to get selected row index from in my bean.

In backing bean i use listener

public void updateCurrent()
{
   int rowIndex = dataTable.getRowIndex();
   ...
}

but i always get -1 in rowIndex

in p:dataTable i try process my DataTable and call listener on select row

<p:ajax event="rowSelect" listener="#{locationBean.updateCurrent}" 
           process=":mainTab:mainLocationForm:mainLocationTable"/>

PrimeFaces version - 3.4

Please help to get selected row index. Thanks.

1
A guess in the wild: did you bind the dataTable in your xhtml like this: <p:dataTable binding="#{yourBean.myDataTable}" />?Jens
@Jens Yes. I bind it. And checked that setter for dataTable called when i process :mainTab:mainLocationForm:mainLocationTableesedin
The method description on getRowIndex() says this: "This property is not enabled for value binding expressions."Jens

1 Answers

0
votes

I'm not so sure that your way is the right way to retrieve the rowIndex. Somehow the browser and the server need to synchronize the currently selected row (in the browser) and I don't see how this works.

Maybe this can/should be done differently by using the listener parameter org.primefaces.event.SelectEvent

You could extend your public void updateCurrent() method to this:

public void updateCurrent(SelectEvent mySelectEvent) {
   // use the mySelectEvent.getObject() method in here and 
   // check what this object has to offer
}

I haven't tried this and can therefore not verify if the object that you get has the rowIndex (somehow). But you could easily try this yourself.

EDIT: Also check out this question and the answer from balusC: How to get selected row index in JSF datatable?