You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Belfer-Shevett <db...@homeport.org> on 2008/04/08 01:18:47 UTC
Noob question(s). Interceptor breaking forms, and Connection handling?
Hi folks, I have two questions, and I apologize for the n00b approach.
I'm just teaching myself struts2, coming from a PHP background (but I've
done plenty of JEE and Java Swing programming, so the language isn't
completely alien :)
Question 1...
I have a Logon form that works fine without an interceptor, but as soon
as I add one, my getUsername() and other methods fail (the username is
null).
Struts.xml:
http://pastebin.stonekeep.com/1893
DBInterceptor:
http://pastebin.stonekeep.com/1894
Logon.java:
http://pastebin.stonekeep.com/1895
If I uncomment the interceptor line in my struts.xml file, the Logon
form validator fails. Line 29 shows 'null' in Logon.java. If i leave
it commented out, it works fine.
Question 2...
In Logon.java, I'm using the execute() method to set up my JDBC
connection (as pulled from my JBoss container datasource), setting up
the Connection, and making the call. Wouldn't it make more sense to do
that in an interceptor around every class, and do something like
ic = new InitialContext();
dataSource = (DataSource)ic.lookup("java:JQuoDEV");
c = dataSource.getConnection();
Logon action = (Logon)invocation.getAction();
action.connection = c;
return invocation.invoke() ;
I tried doing this, and saw the connection start up, but the Action
class kept having the connection as 'null'. I think I'm either
misunderstanding how the interceptor / action sequence works, or doing
something blatantly stupid.
Help?
-dbs
--
Dave Belfer-Shevet
Stonekeep Consulting, Inc
http://www.stonekeep.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Noob question(s). Interceptor breaking forms, and Connection handling?
Posted by Dave Newton <ne...@yahoo.com>.
--- Dave Belfer-Shevett <db...@homeport.org> wrote:
> I have a Logon form that works fine without an interceptor, but as soon
> as I add one, my getUsername() and other methods fail (the username is
> null).
When you declare interceptor-refs for an action you are declaring *all* the
interceptors for that action. You either need to create a *complete* stack
with your interceptor included or specify *all* the interceptors your action
requires.
> Question 2...
> I tried doing this, and saw the connection start up, but the Action
> class kept having the connection as 'null'. I think I'm either
> misunderstanding how the interceptor / action sequence works, or doing
> something blatantly stupid.
Without the actual implementation it will be difficult to help.
What you probably meant in the code above was that you'd check for an
interface that informs the interceptor that the action accepts a connection
property. If the action being invoked implements the interface, get the
connection and set it on the action. If you look at many of the S2/XWork
interceptor source you'll see this technique used all over the place.
That's certainly one way to handle connections.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org