I will typically retrieve everything I need to populate the fields in
prepare() and try to do it within a single db transaction.  One issue
with doing db retrieval from within a getter is the getter may be
called multiple times which would mean repeating db queries
(inefficient) or doing lazy loading (adds complexity).  In most cases
you should know what data the page will need to populate controls etc.
so better just get it all at once.

Summary: I never to db retrieval in a getter, always use prepare().


On Tue, Mar 30, 2010 at 6:37 AM, Alex Rodriguez Lopez
<alo...@flordeutopia.pt> wrote:
> Hi to all,
>
> as I learn more things about S2 some questions emerge about best practices
> more experiences users might know how to do best.
>
> I believe it is a common problem having to populate fields like selects
> first thing (with data from DB or stored in session) before any task is
> done.
>
> This is accomplished by the prepare() method, but I have been doing this too
> directly in getters, so when the form wants the list data they are called
> and if necessary retrieve data from session or DB (all in the getter from
> that property, usually lists for selects).
>
> So why sould I use prepare() to populate things or do it directly in
> getters? What do you use to accomplish this? Advantages of either method?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to