This discussion is archived
0 Replies Latest reply: Dec 27, 2012 6:19 PM by user20090209 RSS

Datatable selected row not available when user selects for first time

user20090209 Newbie
Currently Being Moderated
Hello

In my managed bean I have @ViewAccessScoped, I have noticed that when user selects a row from a datatable for the first time, the selected row is not available in managed bean, however for subsequent selections, selected row value is available in managed bean.

If I use session scope, then for the first time itself I am able to get the selected row value.

What could be the reason for this?
@Named("emp")
@ViewAccessScoped
public class EmployeeManagedBean implements Serializable {

private Employee selectedRequest = new Employee();

@PostConstruct
   public void init() {
      initTable();
   }

   private void initTable() {
      lazyModel = new LazyEmployeeDataModel(requestList, requestService);
   }

   public LazyDataModel<Employee> getLazyModel() {
      return lazyModel;

   }
and onRowSelect Method
public void onRowSelect(SelectEvent event) {
      try {
         setSelectedRequest((Employee) event.getObject());
         System.out.println("row "
               + getSelectedRequest()); 
JSF Code
<p:dataTable id="dataTable" var="req" lazy="true" value="#{emp.lazyModel}"
      rowKey="#{req.empNo}"
         paginator="true" rows="10"
         selection="#{emp.selectedRequest}">                  
      <p:ajax event="rowSelectRadio" listener="#{emp.onRowSelect}" /> 
       <p:column selectionMode="single" style="width:18px" />  

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points