On 7/6/06, Garner Shawn <[EMAIL PROTECTED]> wrote:
I was going to do that in the init method of the viewcontroller
interface for the bean init method unless you have another better
place to do it?
That works, but it'll get executed once per request rather than once at
startup.
I'm just going to do a Hibernate query which should return a list.
What I've done recently is to use the following strategy:
* Create an application-scoped managed bean named "domains" to
hold all the cached static stuff my app needs throughout its lifetime.
* Make the implementation class extend AbstractApplicationBean
(a fairly recent addition to Shale) so that it also gets an init() and
destroy() method ... but this time they correspond to application
startup and shutdown.
* Do the Hibernate or whatever queries either in the init() method
of the domains bean, or lazily in the getter for a particular list.
* Add methods like getProductList() to this bean, so I can reference
it with expressions like "#{domains.productList}".
* If you happen to be running on Java SE 5 or later, make the return
type of this method List<Product> instead of just List ... that'll make
programmatic access to the data much nicer (no casts needed).
Doing things this way, you can also get fancier and make the getters smart
about checking for whether they should reload the database data (either
because it's been a long time since the last reload, or because a cheap
query returned a flag that you set to say "update the cached data"), without
the rest of the application even knowing what is going on.
Craig
On 7/6/06, Craig McClanahan <[EMAIL PROTECTED]> wrote:
> On 7/6/06, Garner Shawn <[EMAIL PROTECTED]> wrote:
> >
> > so in my dataList I can do #{welcome$products.productsList}
> >
> > <managed-bean>
> >
<managed-bean-name>productsMangedBean</managed-bean-name>
> > <managed-bean-class>java.util.ArrayList
> > </managed-bean-class>
> > <managed-bean-scope>application</managed-bean-scope>
> > </managed-bean>
> >
> > <managed-bean>
> >
<managed-bean-name>welcome$products</managed-bean-name>
> > <managed-bean-class>
> > com.age.j.soft.beans.ProductBackingBean</managed-bean-class>
> > <managed-bean-scope>request</managed-bean-scope>
> > <managed-property>
> > <property-name>productsList</property-name>
> > <property-class>java.lang.ArrayList
> > </property-class>
> > <value>#{productsMangedBean}</value>
> > </managed-property>
> > </managed-bean>
> >
> > then com.age.j.soft.beans.ProductBackingBean can implement the
> > viewcontroller interface to get init called to populate the list
> > before the view is rendered.
> >
> > Does this look about right?
>
>
> Yep ... that should all work, although you could also bind your view
> components directly to #{productsManagedBean} if you wanted to, and
avoid
> the need for the extra level of indirection.
>
> I also presume you have some initialization mechanism that populates the
> actual list elements for "productsManagedBean" someplace?
>
> Shawn
> >
>
>
> Craig
>
>