Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces selected row is null when variable is declared as Long

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" />
like image 743
Jacob Avatar asked Jan 15 '23 00:01

Jacob


2 Answers

  1. You must have a Valid Primary Key in rowKey field.
  2. You must include the dataTable into a form.

Else return set(null).

like image 100
nick Avatar answered Jan 19 '23 12:01

nick


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?

like image 23
partlov Avatar answered Jan 19 '23 11:01

partlov