You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Rodriguez Lopez <al...@flordeutopia.pt> on 2010/03/30 12:37:36 UTC

Populate: Implement preparable or richer getter approach

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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Populate: Implement preparable or richer getter approach

Posted by Greg Lindholm <gr...@gmail.com>.
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
<al...@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: Populate: Implement preparable or richer getter approach

Posted by Paweł Wielgus <po...@gmail.com>.
Hi Alex,
if i would take your code and try to change something,
i would lose some time to find where this damn select options come from,
of course getter would be the last place to check.
That's the only real con that i can think of.

Best greetings,
Paweł Wielgus.


2010/3/30 Alex Rodriguez Lopez <al...@flordeutopia.pt>:
> 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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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