You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Igor Milina <ig...@yahoo.com> on 2005/08/09 16:40:42 UTC

Getter called in APPLY_REQUEST_VALUES phase?

Hello,

I have a datatable on my JSP page that displays list
of employees. This datatable has only outputText
components for displaying data. Value binding is
something like:
value="#{employees.listOfEmployees}"

Inside employees bean there is getter for
listOfEmployees:

public List getListOfEmployees() {
return getListFromDatabase();
}

When my page is displayed, this getter will be called
in RENDER_RESPONSE phase. This is expected behaviour,
since my datatable needs to be populated before it is
displayed to the user.

My problem is following:
When I submit this page, getter getListOfEmployees
will be called again in APPLY_REQUEST_VALUES phase,
doing unnecessary database retreival. Why is this
happening? I understand that getters (and setters)
must be called for all properties that needs to be
updated via submitted values, but there is no control
on my JSP that updates value of my listOfEmployees
(only datatable and its outputTexts).

Moreover, listOfEmployees does not have any setter, so
I don't see any reason JSF should do anything with it
inside APPLY_REQUEST_VALUES.
Is there any workaround this problem?

Thank you for any help, 
Igor.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: Getter called in APPLY_REQUEST_VALUES phase?

Posted by Mike Kienenberger <mk...@gmail.com>.
This general topic has come up a few times before.

Do a search for the myfaces user mailing list messages with a subject
of  "getter/setter, lifecycle" on June 14th/15th for a pretty good
discussion.

In summary, there are no limitations in JSF on how many times a getter
might be called.
If you are doing something complex, fragile, or expensive in your
getter, then you need to handle it in yourself  (caching the result
after the first call is one solution).   This is good practice even
outside of JSF.

-Mike

On 8/9/05, Igor Milina <ig...@yahoo.com> wrote:
> Hello,
> 
> I have a datatable on my JSP page that displays list
> of employees. This datatable has only outputText
> components for displaying data. Value binding is
> something like:
> value="#{employees.listOfEmployees}"
> 
> Inside employees bean there is getter for
> listOfEmployees:
> 
> public List getListOfEmployees() {
> return getListFromDatabase();
> }
> 
> When my page is displayed, this getter will be called
> in RENDER_RESPONSE phase. This is expected behaviour,
> since my datatable needs to be populated before it is
> displayed to the user.
> 
> My problem is following:
> When I submit this page, getter getListOfEmployees
> will be called again in APPLY_REQUEST_VALUES phase,
> doing unnecessary database retreival. Why is this
> happening? I understand that getters (and setters)
> must be called for all properties that needs to be
> updated via submitted values, but there is no control
> on my JSP that updates value of my listOfEmployees
> (only datatable and its outputTexts).
> 
> Moreover, listOfEmployees does not have any setter, so
> I don't see any reason JSF should do anything with it
> inside APPLY_REQUEST_VALUES.
> Is there any workaround this problem?
> 
> Thank you for any help,
> Igor.
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>