Re: RE: Re: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-11 Thread Tapestry User List

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:


  

  



  

  


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:
> > ...
> > 
> >  > scope="application">
> >  > class="ns.MyApplicationObject"/>
> > 
> > 
> > ...
> >
> > 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]



Re: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread Shing Hing Man
I have used the following piece of code to retrieved
an 
application ASO  in a
HttpSessionListener.sessionCreated method.
It might work in ServletContextListener as well.

// context is the servlet context
Registry registry = (Registry) context

.getAttribute(ApplicationServlet.REGISTRY_KEY_PREFIX_PUBLIC
+ "(the name of 
ApplicationServlet given in
web.xml");

ApplicationStateManager manager  =
(ApplicationStateManager)

registry.getService("tapestry.state.ApplicationStateManager",
ApplicationStateManager.class);
MyApplicationObject myASO =
(MyApplicationObject)manager.get("myApplicationObject");


HTH
Shing


--- Tapestry User List <[EMAIL PROTECTED]>
wrote:

> 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:
> ...
> 
configuration-id="tapestry.state.ApplicationObjects">
>scope="application">
>   
>
> 
> ...
> 
> Thanks so much,
> 
> D.
> 
>
-
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 


Home page :
  http://uk.geocities.com/matmsh/index.html

Send instant messages to your online friends http://uk.messenger.yahoo.com 

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



RE: Re: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread Ben Dotte
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:


  

  



  

  


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:
> > ...
> > 
> >  > scope="application">
> >  > class="ns.MyApplicationObject"/>
> > 
> > 
> > ...
> >
> > 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]



Re: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread Mahmut Izci

Hi,

how about using an InjectState annotation:

  @InjectState("MyApplicationObject")
   public abstract MyApplicationObject getMyApplicationObject();

Maybe this works.

Regards
Mahmut


Tapestry User List schrieb:

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:
> ...
> 
>  scope="application">
>  class="ns.MyApplicationObject"/>
> 
> 
> ...
>
> 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]



Re: Re: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread Tapestry User List

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:
> ...
> 
>  scope="application">
>  class="ns.MyApplicationObject"/>
> 
> 
> ...
>
> 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]



Re: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread James Carman

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





...

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]



RE: how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread Ben Dotte
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:
...



 

...

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]



how to retrieve an Application State Object (ASO) with an application scope from the ServletContext ?

2007-01-04 Thread Tapestry User List

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



   

...

Thanks so much,

D.

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