Yes I think this is correct.

If you really want to get fancy you could use JNDI to access your global data. This is good for distributed server environment.

As Richard mentioned take care with the Singleton design pattern. In Tomcat if you have the <Context reloadable="true"> you can get ClassCastExceptions with Singleton instances.

regards Malcolm

From: Eric Everman <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: [Tapestry-developer] Global References
Date: Tue, 22 Oct 2002 12:07:04 -0500


Thanks for the replies mb & Malcom.
To summarize the 'scopes' of Tapestry:
-Engine stores page state using a page recorder (Individual Page Scope w/ Session Lifetime)
-Visit stores you business object state (Session Scope)
-Application scope (ie global shared resources) is available thru the Servlet context, which can be accessed via the RequestCycle.
Do I have this correct?
Eric Everman



At 02:57 AM 10/22/2002, you wrote:

Just to add:

In addition to what Malcom suggested, you can get the servlet context in this way as well:
cycle.getRequestContext().getServlet().getServletContext()
and another approach is to use a singleton class outside the Servlet hierarchy.

Best regards,

-mb



Malcolm Edgar <[EMAIL PROTECTED]> wrote:
Subclassing the Engine is a good place for global references. However
remember the Engine is serialized and stored in the user's HttpSession, so
you may want to uses transient in some cases, e.g.

public class MyEngine extends SimpleEngine {

private transient PersistenceManager persistenceManager;

public synchronized PersistenceManager getPersistenceManager() {
if (persistenceManager == null) {
persistenceManager = new PersistenceManager();
}
return persistenceManager;
}

private static final SimpleDateFormat MY_DATE_FORMAT =
new SimpleDateFormat("dd MM yyyy");

public DateFormat getDateFormat() {
return MY_DATE_FORMAT;
}
}

Alternatively you can store global objects in the ServletContext. To access
the ServletContext override the Engine.service() method:

public class MyEngine extends SimpleEngine {

private static final String PM_KEY = "MyEngine.PersistenceManager";

private transient PersistenceManager persistenceManager;

/** @see IEngine#service(RequestContext) */
public boolean service(RequestContext context) throws
ServletException, IOException {

// If not initialized lookup in ServletContext
if (persistenceManager == null) {
ServletContext servletContext =
context.getServlet().getServletContext();

persistenceManager = servletContext.getAttribute(PM_KEY);

// If not found, create and add to ServletContext
if (persistenceManager == null) {
persistenceManager = new PersistenceManager();
servletContext.setAttribute(PM_KEY, persistenceManager);
}
}

super.service(context);
}

public PersistenceManager getPersistenceManager() {
return persistenceManager;
}
}


regard Malcolm Edgar

>From: Eric Everman
>To: [EMAIL PROTECTED]
>Subject: [Tapestry-developer] Global References
>Date: Mon, 21 Oct 2002 21:09:22 -0500
>
>I'm still coming up to speed on Tapestry and I have a general question:
>Where can I store a global reference that can be accessed by all Visit
>objects? I need to store a shared reference to a Hibernate SessionFactory
>so that all Visit objects can access the persistence layer.
>
>Also, is there a good example of the use of ListEdit somewhere (that
>doesn't involve EJB)?
>
>Thanks,
>
>Eric Everman
>
>
>
>-------------------------------------------------------
>This sf.net emial is sponsored by: Influence the future of Java(TM)
>technology. Join the Java Community Process(SM) (JCP(SM)) program now.
>http://ad.doubleclick.net/clk;4699841;7576298;k?http://www.sun.com/javavote
>_______________________________________________
>Tapestry-developer mailing list
>[EMAIL PROTECTED]
>https://lists.sourceforgY! Web Hosting - Let the expert host your web site

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963



-------------------------------------------------------
This sf.net emial is sponsored by: Influence the future of Java(TM) technology. Join the Java Community Process(SM) (JCP(SM)) program now. http://ad.doubleclick.net/clk;4699841;7576301;v?http://www.sun.com/javavote
_______________________________________________
Tapestry-developer mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/tapestry-developer

Reply via email to