myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "h b" <hbmailingl...@gmail.com>
Subject help me decide when to populate my datatable?
Date Wed, 05 Mar 2008 20:20:52 GMT
Hello, I'm new to jsf.

Background:
I have a page that shows a table of items using the datatable component.
The datatable is bound to my backing beans items field. <h:datatable
values="#{myBean.items}"...></h:datatable>.

myBean has a request scope.

myBean.getItems() is implemented as follows:
if (items == null) items = createItems();
return items;

I put in a few log statements to see how everything is working.

What I'm observing:
* The first time the page is rendered myBean.getItems is invoked during the
RENDER_RESPONSE phase.  That's great, it make sense.
* On post back getItems is called during the: APPLY_REQUEST_VALUES &
RENDER_RESPONSE phase.

Questions & Concerns:
1. On postback why is getItems getting invoked during APPLY_REQUEST_VALUES
phase?
2. On postback since myBean has request scope, it is constructed again,
which means items is null until getItems gets called.  This means that (on
postback) during the APPLY_REQUEST_VALUES phase, I'm doing a db fetch to
build my items.  This is not good for me, specially since, I want to respond
to an event (such as new filter criteria) and fetch items based on that
event.  So I'll end up doing 2 fetches.

IOne way to resolve this issue is by changing myBean scope to session
scope.  But I want to stay stateless...and I'm hoping jsf can support a
stateless model.

I'm sure I'm missing something since this is a very simple use-case.

Thanks in advance.

Mime
View raw message