Re: ApplicationAware not triggering setApplication? Or, how best to reference a Connection pool?

2008-06-11 Thread Lukasz Lenart
 My understanding is that the webwork API for ApplicationAware means that the
 interceptor will have it's setApplication(Map applicationData); triggered
 when the interceptor is run, thereby giving me access to the
 applicationcontext.

ApplicationAware should be used with Actions not with interceptors, to
access application just use

public String intercept(ActionInvocation invocation)  {
Map appScope = invocation.getInvocationContext().getApplication();
}


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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



ApplicationAware not triggering setApplication? Or, how best to reference a Connection pool?

2008-06-11 Thread Dave Belfer-Shevett
Hi folks - i'm trying to write an interceptor in struts2 that has access 
to the ApplicationMap in the application context.


My understanding is that the webwork API for ApplicationAware means that 
the interceptor will have it's setApplication(Map applicationData); 
triggered when the interceptor is run, thereby giving me access to the 
applicationcontext.


Problem is, it isn't :)

Here's the relevant parts...

public class DBInterceptor extends AbstractInterceptor implements 
ApplicationAware {


...

@Override
public void setApplication(Map arg0) {
logger.info(Receiving applicationMap...);
this.applicationMap = arg0;
}

That logger is never triggered, 'applicationMap' is always null.

My struts.xml is:
interceptors
	interceptor name=dbsetup		 
class=com.stonekeep.congo.interceptors.DBInterceptor /

interceptor-stack name=mystack
interceptor-ref name=dbsetup /
interceptor-ref name=defaultStack /
/interceptor-stack
/interceptors

(The goal here is to store a c3p0 connection pool object in the 
application context, so that I can get a connection from it on every hit 
- I assume this is the proper way to do this?)


Thanks, any help would be appreciated...

-dbs

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



Re: ApplicationAware not triggering setApplication? Or, how best to reference a Connection pool?

2008-06-11 Thread Jeromy Evans

Dave Belfer-Shevett wrote:
Hi folks - i'm trying to write an interceptor in struts2 that has 
access to the ApplicationMap in the application context.


My understanding is that the webwork API for ApplicationAware means 
that the interceptor will have it's setApplication(Map 
applicationData); triggered when the interceptor is run, thereby 
giving me access to the applicationcontext.




The ApplicationAware interface only applies to actions.  It's actually a 
feature of the ServletConfigInterceptor.  That interceptor inspects the 
target action for the interface and injects the Map if present.


XWork's dependency injection uses the @Inject annotation on properties 
and constructions.  It can inject beans it knows of, however the 
application context is not one of them.


The simplest way to access the application context in your interceptor 
is via the ActionInvocation argument:


ie. Map applicationContext = 
actionInvocation.getIncovationContext().getApplication();


You can also inject beans directly into you interceptor via spring or 
guice if you're using one of those DI frameworks.


Hope that helps,
Jeromy Evans


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



Re: ApplicationAware not triggering setApplication? Or, how best to reference a Connection pool?

2008-06-11 Thread Dave Belfer-Shevett

Lukasz Lenart wrote:

My understanding is that the webwork API for ApplicationAware means that the
interceptor will have it's setApplication(Map applicationData); triggered
when the interceptor is run, thereby giving me access to the
applicationcontext.


ApplicationAware should be used with Actions not with interceptors, to
access application just use

public String intercept(ActionInvocation invocation)  {
Map appScope = invocation.getInvocationContext().getApplication();
}


That's done it, thank you very much.  I was really stymied.

-dbs

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