Re: Global concept

"Malcolm Edgar" <[email protected]> Tue, 31 Dec 2002 05:06:07 +0800
Newsgroups gmane.comp.java.tapestry.contrib
Message-ID <[email protected]>
The advantages I see with the global object include:

* Convenient access. This object can be accessed in pages using property 
paths as is done with the Visit object.

* More OO than the stashing various objects in ServletContext bucket under 
various keys. Similiar in concept to Visit vs HttpSession attributes

* Slightly better type safety than ServletContext bucket method, as you are 
only casting to one class. Similiar in concept to Visit vs HttpSession 
attributes

* Avoids classloader issues of Singletons. I have been burnt doing this in 
the past with dynamic classloaders. However, if it works for you that is 
great.

* Global object doesn't have to worry about serialization/transient stuff, 
as does instance variables in SimpleEngine sub classses.

I was doing similar stuff to your FlockTapestryEngine in my code. I was 
initializing a PersistenceManager in the Servlet.init(), placing it in the 
ServletContext, placing it into a SimpleEngine subclass instance variable 
after grabbing it service method, having a BasePage subclass provide an 
convenience method.

What I was hoping was to avoid having to write all the above code, and just 
declaring the thing's classname in the Application.specification and then 
accessing via IPage.

regards Malcolm

p.s. Marvin is cool

>From: [email protected]
>To: "Howard M. Lewis Ship" <[email protected]>,"Malcolm Edgar" 
><[email protected]>,"Tapestry Contrib" 
><tapestry-contrib-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
>Subject: Re: [Tapestry-contrib] Global concept
>Date: Mon, 30 Dec 2002 09:40:36 -0500
>
>hi,
>
>perhaps i'm a little daft, but i dont get it... if - as you said below -
>you're creating it as a singleton, why do you even need framework support
>for it, instead of just writing MyFoo.getInstance()?
>
>i'm aware, there are some classloading issues with a singleton (although
>this has not come up as a problem for me in recent containers), so i keep
>my stuff in the ServletContext as it's supposed to be - but since that
>would be inconvenient to access, i usually wrap my stuff around with some
>code that sets it up as a ThreadLocal (that is statically accessible)...
>so it becomes very convenient to access (anywhere with no casting), since
>i can still say MyFoo.getInstance(), and have the flexibility as to where
>it's really coming from (eg. it doesnt strictly need to be "global")...
>also, i have some concerns about having only one global... you would
>probably need a Map of them... and you still need to the casting
>everywhere you need it...
>
>so, i wouldn't bother to add this to the Tapestry framework itself, it
>already supports what you need, here's an example:
>http://flock.sourceforge.net/xref/net/sf/flock/webapp/FlockTapestryEngine.html
>http://flock.sourceforge.net/xref/net/sf/flock/webapp/FlockContext.html
>
>... and you set it up in the application servlet init() for example, or
>lazy-init, or whatever works for you.
>
>best regards,
>     viktor
>
>On Mon, 30 Dec 2002 06:37:36 -0500, "Howard M. Lewis Ship"
><[email protected]> said:
> > A very good idea, I think.
> >
> > ----- Original Message -----
> > From: "Malcolm Edgar" <[email protected]>
> > To: <tapestry-contrib-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
> > Sent: Monday, December 30, 2002 5:59 AM
> > Subject: [Tapestry-contrib] Global concept
> >
> >
> > > After Howards email about Visit object names including Global, I 
>started
> > > thinking it would be really good to have a shared global object in
> > Tapestry.
> > >
> > > I want to kick off a discussion before putting in a Feature Request.
> > >
> > > Regards Malcolm
> > >
> > > Global
> > > ======
> > >
> > > Aim
> > > ---
> > > Provide a shared global object that can be used for globally accessed 
>data
> > > or utility methods. Currently it is recommended that the SimpleEngine 
>be
> > > subclassed to provide a point to hang shared data off, or access 
>global
> > data
> > > via the ServletContext accessed from the IRequestCycle.
> > >
> > > Conceptually it simpler to have a global object available throughout 
>the
> > > framework.
> > >
> > > Design
> > > ------
> > > A global bean object modelled on the access style of the Visit object.
> > >
> > > The global object would have an accessor method added to IPage 
>interface:
> > >
> > > public Object getGlobal();
> > >
> > > This object would be instantiated via a no args condtructor, with the
> > class
> > > name specified in the Application.specification as is done with the 
>visit
> > > object. This object should follow a singleton style design pattern, so
> > their
> > > is only ever one instance available.
> > >
> > > This object should be stored in the ServletContext under the key
> > > 'net.sf.tapestry.global' so that it can potentially be shared with 
>other
> > > Servlet components.
> > >
> > > Scope
> > > -----
> > > Global object: shared application data
> > > Visit object: user specific data
> > > Persistent page properties: user page specific data
> > >
> > > Example Usage
> > > -------------
> > > Application properties
> > > Application constants
> > > Cached data
> > > Connection DataSources
> > >
> > >
> > >
>--
>
>   [email protected]
>
>--
>http://fastmail.fm - Accessible with your email software
>                       or over the web
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Tapestry-contrib mailing list
>Tapestry-contrib-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>https://lists.sourceforge.net/lists/listinfo/tapestry-contrib


_________________________________________________________________
The new MSN 8: smart spam protection and 3 months FREE*.  
http://join.msn.com/?page=features/junkmail&xAPID=42&PS=47575&PI=7324&DI=7474&SU= 
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_smartspamprotection_3mf



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf