Re: [S2] How to get an object from Spring inside an interceptor

2007-05-23 Thread Josh Vickery

Not the most elegant solution, but you can pull the ApplicationContext
from the ServletContext:

ServletContext sc = ServletActionContext.getServletContext();
(ApplicationContext)sc.getAttribute(org.springframework.web.context.WebApplicationContext.ROOT);

Josh

On 5/23/07, Célio Cidral Junior [EMAIL PROTECTED] wrote:

Hi,

I want to implement an OpenInView pattern interceptor involving
Hibernate, but there's a problem. My SessionFactory is both created
and managed by Spring, and my interceptor should have access to that
SessionFactory, however I don't know how to do that. I have already
searched a lot the web and the docs but couldn't find an answer. Does
anybody know if that's possible (and how)?.

Regards,

Célio.

-
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: [S2] How to get an object from Spring inside an interceptor

2007-05-23 Thread Guillaume Carré

2007/5/23, Célio Cidral Junior [EMAIL PROTECTED]:

Hi,

I want to implement an OpenInView pattern interceptor involving
Hibernate, but there's a problem. My SessionFactory is both created
and managed by Spring, and my interceptor should have access to that
SessionFactory, however I don't know how to do that. I have already
searched a lot the web and the docs but couldn't find an answer. Does
anybody know if that's possible (and how)?.


if your SessionFactory is injected in your action, and all your
actions extend AbstractAction for example, that has a
getSessionFactory() method, you can do this:

public String intercept(ActionInvocation invocation) throws Exception {
   Action action = (Action) invocation.getAction();
   if (action instanceof AbstractAction) {
   sessionFactory = ((AbstractAction) action).getSessionFactory();
...
}
--
Guillaume Carré

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



Re: [S2] How to get an object from Spring inside an interceptor

2007-05-23 Thread Célio Cidral Junior

2007/5/23, Guillaume Carré [EMAIL PROTECTED]:

if your SessionFactory is injected in your action, and all your
actions extend AbstractAction for example, that has a
getSessionFactory() method, you can do this:

public String intercept(ActionInvocation invocation) throws Exception {
Action action = (Action) invocation.getAction();
if (action instanceof AbstractAction) {
sessionFactory = ((AbstractAction) action).getSessionFactory();
...
}


The actions are unaware of any Hibernate type.  This is mandatory
since I don't want my actions to depend on a specific persistence
mechanism.  They only see DAO interfaces (which are also not dependent
on any persistence mechanism).

Thanks,

Célio.

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



RE: [S2] How to get an object from Spring inside an interceptor

2007-05-23 Thread Fowler, Perryn

If you use the Spring plugin, you should be able to have your actions and your 
interceptors created by Spring.

Then you can simply configure Spring to create your interceptor already wired 
up with a SessionFactory.

-Original Message-
From: Célio Cidral Junior [mailto:[EMAIL PROTECTED]
Sent: Thursday, 24 May 2007 4:58 AM
To: user@struts.apache.org
Subject: [S2] How to get an object from Spring inside an interceptor


Hi,

I want to implement an OpenInView pattern interceptor involving
Hibernate, but there's a problem. My SessionFactory is both created
and managed by Spring, and my interceptor should have access to that
SessionFactory, however I don't know how to do that. I have already
searched a lot the web and the docs but couldn't find an answer. Does
anybody know if that's possible (and how)?.

Regards,

Célio.

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


This e-mail and any attachments to it (the Communication) is, unless 
otherwise stated, confidential,  may contain copyright material and is for the 
use only of the intended recipient. If you receive the Communication in error, 
please notify the sender immediately by return e-mail, delete the Communication 
and the return e-mail, and do not read, copy, retransmit or otherwise deal with 
it. Any views expressed in the Communication are those of the individual sender 
only, unless expressly stated to be those of Australia and New Zealand Banking 
Group Limited ABN 11 005 357 522, or any of its related entities including ANZ 
National Bank Limited (together ANZ). ANZ does not accept liability in 
connection with the integrity of or errors in the Communication, computer 
virus, data corruption, interference or delay arising from or in respect of the 
Communication.

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