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" />
rowKey field.dataTable into a form.Else return set(null).
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With