3
votes

I want to get the selected row of my dataTable, directly if the user selects a row.

I have added

 <p:dataTable id="dataTableID" var="row"
                    value="#{bean.value}"
                    rowKey="${row.id}"
                    selection="#{bean.selectedValue}" selectionMode="single">

It is just possible to get it after clicking on a button.

1

1 Answers

8
votes

There are two ajax-events for instant row selection in primefaces dataTable. One for the selection and one for the unselection.

<p:dataTable ..>
    <p:ajax event="rowSelect" listener="#{yourBean.someListener}"/>
    ...
</p:dataTable>

Now you can access the selected item (of class Foo) like this:

public void someListener(SelectEvent event) {  
    (Foo) event.getObject()     // cast "Object" to "Foo" 
}  

For additional information take a look at the primefaces showcase first: http://www.primefaces.org/showcase/ui/datatableRowSelectionInstant.jsf