user6580560
user6580560

Reputation:

How can I hand over row object from datatable

I have a PrimeFaces DataTable with a lot of entries. When I click a row I do this here:

<p:ajax event="rowSelect" listener="#{detailsBean.showData(data)}">

So what I want to do is to call a method in my bean and hand over the data from the clicked table row but when I debug it the object is always null. I'm not sure how to deal with this. Whats wrong?

Upvotes: 1

Views: 104

Answers (2)

Sangeeth
Sangeeth

Reputation: 71

Xhtml :

<p:dataTable    value="#{bean.list}" selectionMode="single" selection="{bean.selectedEmployee}">

      <p:ajax event="rowSelect"  listener="#{bean.anyMethod()}"/>

</p:dataTable>

Here ajax is not mandatory

Bean :

 List<Employee> list ;
 Employee selectedEmployee;


 public void anyMethod(){

 }

Upvotes: 0

Blablabla
Blablabla

Reputation: 127

Here's how I get the selected item from datatable

xhtml:

<p:datatable value="#{yourBean.listObject}" selection="single" ---- and other suff---->

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

</p:datatable>

bean:

YourObject yourObject;
List<YourObject> listObject;
-----
public void aMethodInBean(SelectEvent event) {
    yourObject = (YourObject) event.getObject();
}

Upvotes: 1

Related Questions