Primefaces selected row is null when variable is declared as Long

java, jsf, jsf-2, primefaces

Solution

When using selection in `dataTable` you should provide `rowKey` attribute which will be used to find actual object which is selected in your list. That should be property which is unique for all data in list (probably primary key from database):

rowKey="#{emp.employeeNumber}"

I don't know actual reason why this worked with String. Maybe that was part of your `toString()` method?

Problem

I have the following in ManagedBean ``` private Employee selectedEmployee; // with getter and setter public void onRowSelect(SelectEvent event) { System.out.println("selected employee "+selectedEmployee.getEmployeeNumber()); } ``` My problem is in `Employee` Entity class if I make `employeeNumber` from `String` to `Long`, I am getting null for `selectedEmployee` in `onRowSelect` method of ManagedBean Employee Entity class ``` private String employeeNumber; // this works private Long employeeNumber; // this doesn't work ``` What could be the reason for this? JSF Code for selection ``` <p:dataTable id="dataTable" var="emp" lazy="true" value="#{myMB.lazyModel}" styleClass="userDataTableStyle" paginator="true" paginatorPosition="bottom" rows="5" selection="#{myMB.selectedEmployee}"> <p:ajax event="rowSelectRadio" listener="#{myMB.onRowSelect}" update=":myform:details" /> ```

Original source