Ok, I have a bean that needs to populate a table so I was trying to
work with ListDataModel and I can get it to work fine but where I'm
running into 'best practice' difficulties is after doing an update to
an item in the table, I want a fresh population of the ListDataModel
to be used on the resulting JSP.

Here's the problem...

Say I have in my EmployeeListBean ...

private static ListDataModel model =  new ListDataModel(
EmployeeService.getEmployees() );
    
  public ListDataModel getEmployeesModel() {
        return model;
    }

I can use this on a jsp like...

<h:dataTable var="emp" value="#{employeesListBean.employeesModel}" >


However, now I click on a link to edit a row in the table and I pull
the  row in a resulting action...

employee = (EmployeeVO)getEmployeesListBean().getEmployeesModel().getRowData();

I then edit this employee on a resulting editForm and then when I
submit that form, I want to repopulate the ListDataMode from the
database.

I could just add a method to the EmployeeListBean...

public void populateListDataModel() {
   model = EmployeeService.getEmployees();
}

and I can call that after I do an update. The problem is I think this
is a really ugly solution. After doing an upate I shouldn't have to
remember to populate some other dataModel in some other class. The
EmployeeListBean should be able to stand by itself.

Ideally when I do...

<h:dataTable var="emp" value="#{employeesListBean.employeesModel}" >

I want a FRESH list of the employeesModel coming from my Service class
(backend call to  populate the list),

If I alter the method getEmployeesModel() to look like:

public ListDataModel getEmployeesModel() {
   model = EmployeeService.getEmployees();
}

that'll work fine for the list population on the JSP, but I'll of
course still need a method to get back the actually model that is on
the JSP for when I click on the row and need to get that actual model
that has the row I selected?

How do I set this object up so that I have a method that populates a
fresh list on my JSP and also has a handle to get the listModel so
that I can call it and get the rowData I need?

Reply via email to