myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "CONNER, BRENDAN \(SBCSI\)" <bc1...@sbc.com>
Subject RE: more on architecture really confused on something (shocker:)
Date Thu, 01 Sep 2005 19:39:40 GMT
Are you trying to do everything in EmployeeListBean, or do you have an
EmployeeListAction class to handle actions (e.g., looking up an
employee's information, processing "Save") separate from the data?  If
you have a separate EmployeeListAction bean that has a managed property
reference to EmployeeListBean, then, when the Action is called with the
"Save", it can invoke a method on the EmployeeListBean to reset its
data, passing the new list of data as an argument.

That's the approach we follow, anyway.

- Brendan

-----Original Message-----
From: Rick Reumann [mailto:rick.reumann@gmail.com] 
Sent: Thursday, September 01, 2005 1:53 PM
To: MyFaces Discussion
Subject: more on architecture really confused on something (shocker:)


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?

Mime
View raw message