On Thu, 08 Jun 2006 13:05:40 -0400, Andrus Adamchik
<andru..bjectstyle.org> wrote:
> Current example puts it in the visit. I would personally use a regular
> web app setup with Cayenne filter (making Tapestry app just another web
> app case as far as Cayenne is concerned). I wonder what others are doing
> in this respect? Any HiveMind magic?
I've actually been meaning to write up a page about this. I took a
slightly different approach from what others had done (at least on any of
the pages I visited), so I wanted to get a little feedback too.
I have the following for creating DC instances:
public class DataContextFactory implements StateObjectFactory
{
public Object createStateObject()
{
return DataContext.createDataContext();
}
}
Then I define a service so I can inject a DC wherever I want one:
<!-- Factory for creating DataContext instances. -->
<service-point id="dataContextFactory"
interface="com.servprise.www.services.DataContextFactory">
<create-instance
class="com.servprise.www.services.DataContextFactory"/>
</service-point>
For example, this service is used to make a HiveMind contribution for a
global DC. This DC is used for pulling out common DB items, like product
information from a store page. Note the scope ensures the same DC is used
every time.
<!-- Set up the global DataContext for "static" DB entries (e.g., items
in the store page.) -->
<contribution configuration-id="tapestry.state.ApplicationObjects">
<state-object name="global-data-context" scope="application">
<invoke-factory object="service:dataContextFactory"/>
</state-object>
</contribution>
I access this through a base ApplicationPage class like so:
..njectState("global-data-context")
public abstract DataContext getGlobalDataContext();
The service can also be used to inject DCs wherever you'd like (actually,
you'll be inject the DataContextFactory, but you get the idea).
So far, this has been working out pretty well for me. It's simple, and
HiveMind manages the lifecycle stuff for me. I would appreciate any
comments on this approach though.
-- Kevin
This archive was generated by hypermail 2.0.0 : Fri Jun 09 2006 - 12:42:28 EDT