You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrus Adamchik <an...@objectstyle.org> on 2006/06/08 19:05:40 UTC

Tapestry tutorial advice

I am reworking Cayenne tutorials for 1.2 final release. Since I  
haven't used Tapestry for almost a year, and totally missed on 4.0, I  
wanted to get some feedback from Cayenne/Tapestry users. What are the  
good ways to bind DataContext to a session?

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?

Andrus

Re: Tapestry tutorial advice

Posted by Lindsay Steele <ls...@iinet.net.au>.
Personally I just use DataContext.getThreadDataContext() but I am 
interested in what others do.

This is maybe a good one for the Tapestry lists.

Andrus Adamchik wrote:
> I am reworking Cayenne tutorials for 1.2 final release. Since I 
> haven't used Tapestry for almost a year, and totally missed on 4.0, I 
> wanted to get some feedback from Cayenne/Tapestry users. What are the 
> good ways to bind DataContext to a session?
>
> 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?
>
> Andrus
>
>


Re: Tapestry tutorial advice

Posted by Kevin Menard <km...@servprise.com>.
On Fri, 09 Jun 2006 12:41:59 -0400, Kevin Menard <km...@servprise.com>  
wrote:

> 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).

Eh, sure enough, right after posting that I realized a mistake.  You can  
make a HiveMind contribution for a session-bound ASO, too.  Then you can  
inject that ASO into your page.  So, I have an application-bound global DC  
and a session-bound DC.  The fact they're being retrieved via a factory is  
transparent, other than the HiveMind configuration.

-- 
Kevin


Re: Tapestry tutorial advice

Posted by Kevin Menard <km...@servprise.com>.
On Thu, 08 Jun 2006 13:05:40 -0400, Andrus Adamchik  
<an...@objectstyle.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:

   @InjectState("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



RE: Tapestry tutorial advice

Posted by "Gentry, Michael (Contractor)" <mi...@fanniemae.com>.
Doing the <inject/> is fine for smaller applications (examples), but
isn't as nice when you have a lot of pages.  I tried making a
base/superclass page and putting the <inject/> in it, but that doesn't
inherit.  I have to admit I still don't fully understand the craze over
injection/etc.  I have no problems with asking my framework for the
session and it providing it to me using subclassing.  The solution I
came up with is much more convoluted.

/dev/mrg


-----Original Message-----
From: Eric Schneider [mailto:eric.j.schneider@gmail.com] 
Sent: Thursday, June 08, 2006 2:28 PM
To: cayenne-user@incubator.apache.org
Subject: Re: Tapestry tutorial advice


Andrus,

We're still using 1.4, so this is how we do it.

Create a class, like Session.java (with a DataContext instance
variable).   In the <appname>.application file you add the following
line:

<meta key="org.apache.tapestry.visit-class"
value="com.nhl.cmseditor.Session"/>

In MyPage.java

public abstract Object getSession();

In MyPage.page

<inject property="session" type="state" object="visit"/>

I think that's it.

e.



On 6/8/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> I am reworking Cayenne tutorials for 1.2 final release. Since I
> haven't used Tapestry for almost a year, and totally missed on 4.0, I
> wanted to get some feedback from Cayenne/Tapestry users. What are the
> good ways to bind DataContext to a session?
>
> 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?
>
> Andrus
>

Re: Tapestry tutorial advice

Posted by Eric Schneider <er...@gmail.com>.
Andrus,

We're still using 1.4, so this is how we do it.

Create a class, like Session.java (with a DataContext instance
variable).   In the <appname>.application file you add the following
line:

<meta key="org.apache.tapestry.visit-class" value="com.nhl.cmseditor.Session"/>

In MyPage.java

public abstract Object getSession();

In MyPage.page

<inject property="session" type="state" object="visit"/>

I think that's it.

e.



On 6/8/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> I am reworking Cayenne tutorials for 1.2 final release. Since I
> haven't used Tapestry for almost a year, and totally missed on 4.0, I
> wanted to get some feedback from Cayenne/Tapestry users. What are the
> good ways to bind DataContext to a session?
>
> 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?
>
> Andrus
>

RE: Tapestry tutorial advice

Posted by "Gentry, Michael (Contractor)" <mi...@fanniemae.com>.
I might be mistaken, but I thought the web filter and
getThreadDataContext() used the session (HttpSession)?  My applications
are session-oriented, so I definitely want a DC in the session
somewhere.  If you don't care about sessions too much, you can probably
get away with creating a new DC every request.

/dev/mrg


-----Original Message-----
From: Jeff de Vries [mailto:jdevries@pfrog.com] 
Sent: Thursday, June 08, 2006 4:37 PM
To: cayenne-user@incubator.apache.org
Subject: Re: Tapestry tutorial advice


We use Tapestry 3, and just use the standard Cayenne web filter and 
DataContext.getThreadDataContext().  Works fine.  Not really sure why 
you *want* to store the DC in the session ...

Jeff

Andrus Adamchik wrote:
> I am reworking Cayenne tutorials for 1.2 final release. Since I 
> haven't used Tapestry for almost a year, and totally missed on 4.0, I 
> wanted to get some feedback from Cayenne/Tapestry users. What are the 
> good ways to bind DataContext to a session?
>
> 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?
>
> Andrus

Re: Tapestry tutorial advice

Posted by Jeff de Vries <jd...@pfrog.com>.
We use Tapestry 3, and just use the standard Cayenne web filter and 
DataContext.getThreadDataContext().  Works fine.  Not really sure why 
you *want* to store the DC in the session ...

Jeff

Andrus Adamchik wrote:
> I am reworking Cayenne tutorials for 1.2 final release. Since I 
> haven't used Tapestry for almost a year, and totally missed on 4.0, I 
> wanted to get some feedback from Cayenne/Tapestry users. What are the 
> good ways to bind DataContext to a session?
>
> 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?
>
> Andrus

RE: Tapestry tutorial advice

Posted by "Gentry, Michael (Contractor)" <mi...@fanniemae.com>.
Well, if you are on Java 1.5, you can use annotations to bind a HiveMind
created session into your page.  I don't have 1.5 of my server, so I had
to do it the hard way.  Took me a while.  (I didn't want deprecation
errors from using getVisit().)  I know have a
getSession().getDataContext() for my use.  This felt "right" to me due
to my WebObjects background.  I never tried doing anything with a
servlet filter.  I'd like to hear other thoughts, too.

/dev/mrg


-----Original Message-----
From: Andrus Adamchik [mailto:andrus@objectstyle.org] 
Sent: Thursday, June 08, 2006 1:06 PM
To: cayenne-user@incubator.apache.org
Subject: Tapestry tutorial advice


I am reworking Cayenne tutorials for 1.2 final release. Since I  
haven't used Tapestry for almost a year, and totally missed on 4.0, I  
wanted to get some feedback from Cayenne/Tapestry users. What are the  
good ways to bind DataContext to a session?

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?

Andrus