Thanks Ben,

That's what I did and it works great !

Best regards,

D.

2007/1/4, Ben Dotte <[EMAIL PROTECTED]>:
Crap.. I forgot about that dependency on the web request. That never
made sense to me for the case of application-scope ASOs.

In any case, here is a wild idea. If you can capture and hold onto the
Hivemind-created instance of the ASO, you could then give out access to
it through a static getter, similar to a regular old singleton.

To do this you would need to wire up the ASO through a
StateObjectFactory.

So in hivemodule.xml:

<contribution configuration-id="tapestry.state.ApplicationObjects">
  <state-object name="myApplicationObject" scope="application">
    <invoke-factory object="service:stateFactory" />
  </state-object>
</contribution>

<service-point id="stateFactory"
interface="org.apache.tapestry.engine.state.StateObjectFactory">
  <invoke-factory>
    <construct class="ns.MyAppObjectFactory" />
  </invoke-factory>
</service-point>

In MyAppObjectFactory you can instantiate the object you want to use as
an ASO:

public class MyAppObjectFactory implements StateObjectFactory
{
  public Object createStateObject()
  {
    return new MyApplicationObject();
  }
}

Then in MyApplicationObject you could store the instance that gets
created:

public class MyApplicationObject
{
  private static MyApplicationObject instance;

  public MyApplicationObject()
  {
    instance = this;
  }

  public static MyApplicationObject getInstance()
  {
    return instance;
  }
}

Then in your ServletContextListener you can just call
MyApplicationObject.getInstance().

Not the prettiest solution but I believe this would work.

Ben

-----Original Message-----
From: Tapestry User List [mailto:[EMAIL PROTECTED]
Sent: Thursday, January 04, 2007 9:19 AM
To: Tapestry users
Subject: Re: Re: how to retrieve an Application State Object (ASO) with
an application scope from the ServletContext ?

It doesn't work.
Registry registry =
(Registry)context.getAttribute("org.apache.tapestry.Registry:app");
returns null.

D.

2007/1/4, James Carman <[EMAIL PROTECTED]>:
> I don't think that'll work.  The ApplicationStateManager needs a
> reference to the current web request (eventually the session).
>
>
> On 1/4/07, Ben Dotte <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > You could do something like this:
> >
> > ((ApplicationStateManager) ((Registry)
> >
context.getAttribute("org.apache.tapestry.Registry:app")).getService(App
> > licationStateManager.class)).get("myStateObject");
> >
> > Where "myStateObject" is the name of your ASO.
> >
> > HTH
> >
> > Ben
> >
> > -----Original Message-----
> > From: Tapestry User List [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, January 04, 2007 8:45 AM
> > To: tapestry-user@jakarta.apache.org
> > Subject: how to retrieve an Application State Object (ASO) with an
> > application scope from the ServletContext ?
> >
> > Hi,
> >
> > Happy new year !!!!
> >
> > I have created a class that implements ServletContextListener.
> > In the method public void contextDestroyed(ServletContextEvent
event),
> > I need to retrieve an Application State Object (ASO) of tapestry 4
> > with an application scope (not session).
> >
> > My question is how to retrieve an Application State Object (ASO)
from
> > the ServletContext ?
> >
> >
> > public void contextDestroyed(ServletContextEvent event) {
> >       ServletContext context = event.getServletContext();
> >       // retrieve myApplicationObject here
> > }
> >
> > In hivemodule.xml:
> > ...
> > <contribution configuration-id="tapestry.state.ApplicationObjects">
> >                 <state-object name="myApplicationObject"
> > scope="application">
> >                         <create-instance
> > class="ns.MyApplicationObject"/>
> >                 </state-object>
> > </contribution>
> > ...
> >
> > Thanks so much,
> >
> > D.
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to