You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rick Reumann <ri...@gmail.com> on 2005/09/01 20:52:36 UTC

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?

Re: more on architecture really confused on something (shocker:)

Posted by Zhong Li <we...@gmail.com>.
I don't use Model too much, my view is, if you keep it in session scope, you 
can use it, if not, use parameter instead of it. I bumped some issue for 
data in request scope, sometime, it is different result when you use action 
and actionLisener, also for popup window, you will head on troubles. If JSF 
can do better, we can get rid of parameter passing, but now I am afraid not. 




On 9/1/05, Rick Reumann <ri...@gmail.com> wrote:
> 
> On 9/1/05, Zhong Li <we...@gmail.com> wrote:
> 
> > Back to the topic, the key thing is if you want use JSF, you have to 
> keep
> > database operation far from JSF beans.
> 
> I agree totally, but this doesn't help much with this question too much.
> 
> I'm using a ListDataModel just to display the stuff in the the table
> since everyone seemed to agree that using DataModel and getting out
> the selected row is better than my initial plan to simply pass the
> "id/primary key" from a commandLink on the row you want to click on.
> 
> Zhong,
> 
> I'm confused what you are stating, do you not use the DataModel
> approach? How do you get from your master list of items to the edit
> detail page?
>

Re: more on architecture really confused on something (shocker:)

Posted by "ir. ing. Jan Dockx" <ja...@mac.com>.
Using a commandLink with the id/PK is not an option for navigation to 
the detail. First, it has to be passed as a hidden field over the HTML 
page - HTTP request. How are you going to get at that argument? (we 
solved this, but it is ugly). Second, you still go to the same "viewId" 
when clicking a command link, and this means all components for all 
rows in the datamodel are still accessed for all phases on the submit. 
So you still need the data, and iterating over large collections takes 
oodles of time.

We're doing this too now, but actually, it doesn't solve didley.

We will be looking at using outputLink in a few days. This WILL mean 
that the URL changes, and that the id/PK will be visible to the end 
user.

On 1 Sep 2005, at 21:44, Rick Reumann wrote:

> On 9/1/05, Zhong Li <we...@gmail.com> wrote:
>
>>  Back to  the topic, the key thing is  if you want use JSF, you have 
>> to keep
>> database operation far from JSF beans.
>
> I agree totally, but this doesn't help much with this question too 
> much.
>
> I'm using a ListDataModel just to display the stuff in the the table
> since everyone seemed to agree that using DataModel and getting out
> the selected row is better than my initial plan to simply pass the
> "id/primary key" from a commandLink on the row you want to click on.
>
> Zhong,
>
> I'm confused what you are stating, do you not use the DataModel
> approach? How do you get from your master list of items to the edit
> detail page?
>
>
Met vriendelijke groeten,

Jan Dockx

PeopleWare NV - Head Office
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66

PeopleWare NV - Branch Office Geel
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25

http://www.peopleware.be/
http://www.mobileware.be/

Re: more on architecture really confused on something (shocker:)

Posted by Rick Reumann <ri...@gmail.com>.
On 9/1/05, Zhong Li <we...@gmail.com> wrote:
 
>  Back to  the topic, the key thing is  if you want use JSF, you have to keep
> database operation far from JSF beans.  

I agree totally, but this doesn't help much with this question too much. 

I'm using a ListDataModel just to display the stuff in the the table
since everyone seemed to agree that using DataModel and getting out
the selected row is better than my initial plan to simply pass the
"id/primary key" from a commandLink on the row you want to click on.

Zhong, 

I'm confused what you are stating, do you not use the DataModel
approach? How do you get from your master list of items to the edit
detail page?

Re: more on architecture really confused on something (shocker:)

Posted by Zhong Li <we...@gmail.com>.
Hi all,

I readed some similar thing about JSF/model/database issues. 

I have a simple and effective "model/architecture" for JSF practice. We have 
developed 4 projects in JSF/OJB. They are all password protected, so I can't 
demo to you. The first 2 projects we bumped lots hard things. JSF still is 
baby, we needs lots of takecare things. I feel and belive, if JSF want to 
continue and make as common tools, we need add lots of functional 
components, not just tag components. This may take a few years. 
Back to the topic, the key thing is if you want use JSF, you have to keep 
database operation far from JSF beans. (I call those beans as FORM BEAN) . 
My model is simple, straight, effective and works, here is basic tiers logic 
:

JSF pages -- {FORM BEAN}* -- {VALUE OBJECT(Abstract)} - {DAO/OJB} - DATABASE

I have a Core packages. for Each of OJB Object, it automatically copy value 
between Value Object and OJB object, using java reffect when it needs. all 
actions/handlers proccess data to FORM BEANs. In form bean you have method 
for saveings, deleting, updating and etc, depends on your business logic, 
you can refresh data from database or just save data in session or request 
scope. 

Remember, the key thing is never have getters/setters tie to DAO/OJB. It 
will cause lots of trouble, including headache one - if dataModel==0 then 
get it. 

Zhong Li

WebJabber.Net * *