myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ondrej Svetlik <ond...@svetlik.info>
Subject Re: getter called few times
Date Thu, 01 Jun 2006 12:52:49 GMT
Furer Alexander wrote:
> The problem is that i have another controls (filter query) on my page, 
> that's why i can't hit DB only when  clients==null (filter values are 
> not updated yet at this phase). Is there any way to get phaseID in 
> getter method of managed bean ?
>  
> Thanks
> 
>     ----- Original Message -----
>     *From:* Cagatay Civici <mailto:cagatay.civici@gmail.com>
>     *To:* MyFaces Discussion <mailto:users@myfaces.apache.org>
>     *Sent:* Thursday, June 01, 2006 2:37 PM
>     *Subject:* Re: getter called few times
> 
>     Hi,
> 
>     There are several reasons why getters are called more than once, for
>     example, checking for value changes, rendering and etc.
> 
>     You can try lazy initialization to fetch only once like;
> 
>     private List clients;
> 
>     public List getClients() {
>      if(clients == null)
>        clients = fetchFromDB();
>     return clients;
>     }
> 
>     First call to the getter will hit the db and set the clients list,
>     other calls will just return the same list and not hit the db.
> 
>     Cagatay
> 
>     On 6/1/06, *Furer Alexander* <alex_s4@bezeqint.net
>     <mailto:alex_s4@bezeqint.net>> wrote:
> 
>         Hi
>         Why getter method of managed bean called few times for
>         particular phase ?
>         I have "clients" (List)  property of managed bean, getter method
>         fetchs List from DB, how can i fetch only once   ?
>         Below  is call trace for it's getter/setter:
>         Thanks
> 
>         BEFORE RESTORE_VIEW(1)
> 
>         setClients, size: 17
> 
>         AFTER RESTORE_VIEW(1)
> 
>         BEFORE APPLY_REQUEST_VALUES(2)
> 
>         getClients, size: 17
> 
>         getClients, size: 17
> 
>         getClients, size: 17
> 
>         AFTER APPLY_REQUEST_VALUES(2)
> 
>         BEFORE PROCESS_VALIDATIONS(3)
> 
>         getClients, size: 17
> 
>         getClients, size: 17
> 
>         AFTER PROCESS_VALIDATIONS(3)
> 
>         BEFORE UPDATE_MODEL_VALUES(4)
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         AFTER UPDATE_MODEL_VALUES(4)
> 
>         BEFORE INVOKE_APPLICATION(5)
> 
>         AFTER INVOKE_APPLICATION(5)
> 
>         BEFORE RENDER_RESPONSE(6)
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         getClients, size: 19
> 
>         AFTER RENDER_RESPONSE(6)
> 
> 

Did you try to set the filter earlier using immediate attribute?

Best regards

Ondrej Svetlik

Mime
View raw message