You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Sundararaman, Anand" <An...@ps.net> on 2009/02/14 16:44:08 UTC
Struts2-Spring Integration Issue
Hello,
I am using Struts2-Spring-Hibernate in my web application.
I have configured the Struts-Spring plugin to make the Spring framework load the action classes. I am facing a problem with the non-execute (do*) methods in my action classes.
In my applicationcontext.xml, if I do not specify any scope for the action classes, I am able to call my non-execute methods action classes. But I need the action classes to be scope=prototype otherwise they are not thread safe. If I configure scope=prototype, the non-execute methods fail to get called when I try to execute a action from the screen. For now I am forced to create seperate action classes for each action on the presentation layer and make them scope=prototype.
It seems to me that I will never be able to use the Struts non-execute (do*) methods, if I integrate with Spring. I need Spring Framework since it helps a lot with hibernate calls.
Would anyone be able to guide me, if I am missing something.
The versions I am using are as follows
Struts 2.1.6
Spring 2.5.6
Hibernate 3.2
Thanks a lot.
Anand
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
Hi,
Here are the files. I have just pasted only the contents to highlight the problem. The CreateUserAction has two methods, execute() and doActivateUser(). The execute is called for "saveUser" action. The doActivateUser() is called for "activateUser" action. If I specify the scope=prototype, the doActivateUser() fails. If I remove the scope=prototype, the doActivateUser() works but I loose thread safety. I want thread safety as well as able to use the do*() methods called from actions.
Struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
<constant name="struts.ui.theme" value="main" />
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory.spring.autoWire" value="name" />
<include file="struts-default.xml"/>
<package name="default" namespace = "/" extends="struts-default">
.........
.........
<action name="newUser">
<result>/jsp/user/userregistration.jsp</result>
</action>
<action name="saveUser" class="createUser">
<result name="success">/jsp/user/saveuser.jsp</result>
<result name="error">/jsp/user/userregistration.jsp</result>
</action>
<action name="activateUser" class="createUser" method="activateUser">
<result name="success">/jsp/user/useractivated.jsp</result>
<result name="error">/jsp/user/login.jsp</result>
</action>
</package>
</struts>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
.....
.......
......
<bean id="createUser" class="CreateUserAction" scope="prototype">
<property name="userService">
<ref bean="userServiceTarget"/>
</property>
</bean>
<bean id="userServiceTarget" class="UserService">
<property name="UserDAO">
<ref bean="UserDAOTarget"/>
</property>
</bean>
<bean id="UserDAOTarget"
class="UserDAO" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
.....
......
</beans>
________________________________________
From: Lukasz Lenart [lukasz.lenart@googlemail.com]
Sent: Saturday, February 14, 2009 10:01 AM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
Could you copy-paste your struts.xml and Spring config regarding actions?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
No I did not try that. I will try that and let you know. Thanks for the help and time.
________________________________________
From: Lukasz Lenart [lukasz.lenart@googlemail.com]
Sent: Saturday, February 14, 2009 10:39 AM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
2009/2/14 Sundararaman, Anand <An...@ps.net>:
> <action name="activateUser" class="createUser" method="activateUser">
> <result name="success">/jsp/user/useractivated.jsp</result>
> <result name="error">/jsp/user/login.jsp</result>
> </action>
> </package>
That's really strange, did you try to use method="doActivateUser" ?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 - After validation failure populating the drop downs
Posted by hernan gonzalez <hg...@gmail.com>.
You should tell us how the dropdowns were populated in the first page.
If only one Action class is involved, and the dropdowns are populated
by reading some attribute of it
(eg: getOptionListForDropDown() which looks at the
optionListForDropDown list )
you should fill that list, not in the action method that is invoked
for generating the
first form page, but in the prepare method, or in the constructor, or
making the getter method a "lazy getter" (my preferred way, in
general; but this depends on the scenario)
Hernán J. González
http://hjg.com.ar/
--
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 - After validation failure populating the drop downs
Posted by Lukasz Lenart <lu...@googlemail.com>.
Implement Preparable interface [1] and take a look on Prepare
interceptor [2], it should be what you want
[1] http://struts.apache.org/2.1.6/struts2-core/apidocs/com/opensymphony/xwork2/Preparable.html
[2] http://struts.apache.org/2.1.6/docs/prepare-interceptor.html
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 - After validation failure populating the drop downs
Posted by Jim Kiley <jh...@summa-tech.com>.
In your action class, write a method like so:
public String input() {
// populate my dropdowns
return Action.INPUT;
}
Obviously you will have to write the code to populate your dropdowns there,
as that depends on what you are up to. But the input() method of your
action class will be called if validation fails, so if you have things that
you want to make sure occur on validation failure, put them there.
jk
On Mon, Mar 2, 2009 at 1:30 PM, Sundararaman, Anand <
Anand.Sundararaman@ps.net> wrote:
> Hi,
> Would you able to specify in little more detail? Sorry for that as I am
> new to Struts 2.
>
> Thanks,
> Anand
>
>
> -----Original Message-----
> From: Jim Kiley [mailto:jhkiley@summa-tech.com]
> Sent: Monday, March 02, 2009 12:23 PM
> To: Struts Users Mailing List
> Subject: Re: Struts 2 - After validation failure populating the drop downs
>
> Populating the dropdowns in an input() method that returns Action.INPUT
> should do the trick.
> jk
>
> On Mon, Mar 2, 2009 at 1:19 PM, Sundararaman, Anand <
> Anand.Sundararaman@ps.net> wrote:
>
> > Hi,
> > I guess there is an elegant solution for this but I could not find out
> in
> > the user list.
> >
> > I am using Struts 2 and creating some form validations. If a validation
> > fails on a JSP screen, the input result takes back the control to the
> same
> > screen, but the drop downs are not populated. I need to know the best way
> of
> > showing the validation failures and also populating the drop downs.
> >
> > Thanks a Lot,
> >
> > Anand
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com
RE: Struts 2 - After validation failure populating the drop downs
Posted by "Sundararaman, Anand" <An...@ps.net>.
Hi,
Would you able to specify in little more detail? Sorry for that as I am new to Struts 2.
Thanks,
Anand
-----Original Message-----
From: Jim Kiley [mailto:jhkiley@summa-tech.com]
Sent: Monday, March 02, 2009 12:23 PM
To: Struts Users Mailing List
Subject: Re: Struts 2 - After validation failure populating the drop downs
Populating the dropdowns in an input() method that returns Action.INPUT
should do the trick.
jk
On Mon, Mar 2, 2009 at 1:19 PM, Sundararaman, Anand <
Anand.Sundararaman@ps.net> wrote:
> Hi,
> I guess there is an elegant solution for this but I could not find out in
> the user list.
>
> I am using Struts 2 and creating some form validations. If a validation
> fails on a JSP screen, the input result takes back the control to the same
> screen, but the drop downs are not populated. I need to know the best way of
> showing the validation failures and also populating the drop downs.
>
> Thanks a Lot,
>
> Anand
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2 - After validation failure populating the drop downs
Posted by Jim Kiley <jh...@summa-tech.com>.
Populating the dropdowns in an input() method that returns Action.INPUT
should do the trick.
jk
On Mon, Mar 2, 2009 at 1:19 PM, Sundararaman, Anand <
Anand.Sundararaman@ps.net> wrote:
> Hi,
> I guess there is an elegant solution for this but I could not find out in
> the user list.
>
> I am using Struts 2 and creating some form validations. If a validation
> fails on a JSP screen, the input result takes back the control to the same
> screen, but the drop downs are not populated. I need to know the best way of
> showing the validation failures and also populating the drop downs.
>
> Thanks a Lot,
>
> Anand
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com
Struts 2 - After validation failure populating the drop downs
Posted by "Sundararaman, Anand" <An...@ps.net>.
Hi,
I guess there is an elegant solution for this but I could not find out in the user list.
I am using Struts 2 and creating some form validations. If a validation fails on a JSP screen, the input result takes back the control to the same screen, but the drop downs are not populated. I need to know the best way of showing the validation failures and also populating the drop downs.
Thanks a Lot,
Anand
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Wes Wannemacher <we...@wantii.com>.
Try using CGLIB proxies rather than Dynamic JDK proxies... I'm
guessing that your methods are not defined in one of the extended
interfaces. Assuming you are using Spring 2.5 or higher, try adding
this to your applicationContext.xml ->
<aop:config proxy-target-class="true" />
Then make sure you have the CGLIB jars available. You also have to
make sure that you have the AOP namespace available... make sure your
<beans /> tag has the following -
<beans
...
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
...
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
It's sort of just a stab, but it seems like whenever I run into a
problem that Spring is not finding methods defined on the bean, I have
to change the proxy type to fix it... Dynamic JDK proxies only expose
methods that are defined as part of an implemented interface, CGLIB
can expose all of the methods, but the downside is that you must have
a no-arg constructor for the bean being proxied... For Struts2
actions, that probably isn't a big deal.
-Wes
On Wed, Feb 18, 2009 at 10:10 AM, Sundararaman, Anand
<An...@ps.net> wrote:
> Hi Dale and Wes,
>
> I am the original poster. But I did get a lot of information in this discussion.
>
> I will like to explain my original issue again.
>
> In my Struts2- Spring2 application, I had configured the struts2-Spring plugin and made Spring initialize all the action classes etc. Basically I configured all the action classes in the applicationContext.xml and all the action classes scoped prototype. But when I try to invoke the non-execute (do*) methods from my screen actions, it was failing with NoSuchMethodException. If I change the scope to singleton it was working fine. But I need the action classes to be prototype for thread safety. So I need a solution for having the action classes scoped prototype and also able to use the non-execute methods. Then I was interested to see if I make the Struts load the action classes, but Spring load the service,DAO etc. and if I can wire them up.
>
> Please let me know if you have better ideas.
>
> Thanks a Lot,
> Anand
>
>
> -----Original Message-----
> From: Dale Newfield [mailto:dale@newfield.org]
> Sent: Tuesday, February 17, 2009 7:08 PM
> To: Struts Users Mailing List
> Subject: Re: Struts2-Spring Integration Issue
>
> Wes Wannemacher wrote:
>> I jumped into the thread late and didn't see your original problems. I tend to
>> peruse for things I can help on, so I'm not sure if I have an answer for your
>> original problem :(
>
> I wasn't the original poster. I don't think I ever saw the original
> message, so let's hope that that person has resolved his or her issue.
> :-) If not, please remind us of what it was! (I'm like you--I don't
> have time to read the full list these days, so I look for messages with
> subject lines on which I might be able to offer advice--in this case I
> took an interest in a thread for selfish reasons rather than helpful ones.)
>
>> Although, there are a few considerations for interceptors and their
>> dependencies (as opposed to actions), especially when dealing with databases.
>> Mainly, an interceptor is a singleton, so, if you are grabbing a resource via
>> spring, and that resource depends on a database resource, could a pool or
>> something be re-claiming it after excessive idle time?
>
> Those are good suggestions--when I do get time to re-focus on this
> problem I'll investigate that angle -- it may well be something like that.
>
> Thanks,
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
Hi Dale and Wes,
I am the original poster. But I did get a lot of information in this discussion.
I will like to explain my original issue again.
In my Struts2- Spring2 application, I had configured the struts2-Spring plugin and made Spring initialize all the action classes etc. Basically I configured all the action classes in the applicationContext.xml and all the action classes scoped prototype. But when I try to invoke the non-execute (do*) methods from my screen actions, it was failing with NoSuchMethodException. If I change the scope to singleton it was working fine. But I need the action classes to be prototype for thread safety. So I need a solution for having the action classes scoped prototype and also able to use the non-execute methods. Then I was interested to see if I make the Struts load the action classes, but Spring load the service,DAO etc. and if I can wire them up.
Please let me know if you have better ideas.
Thanks a Lot,
Anand
-----Original Message-----
From: Dale Newfield [mailto:dale@newfield.org]
Sent: Tuesday, February 17, 2009 7:08 PM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
Wes Wannemacher wrote:
> I jumped into the thread late and didn't see your original problems. I tend to
> peruse for things I can help on, so I'm not sure if I have an answer for your
> original problem :(
I wasn't the original poster. I don't think I ever saw the original
message, so let's hope that that person has resolved his or her issue.
:-) If not, please remind us of what it was! (I'm like you--I don't
have time to read the full list these days, so I look for messages with
subject lines on which I might be able to offer advice--in this case I
took an interest in a thread for selfish reasons rather than helpful ones.)
> Although, there are a few considerations for interceptors and their
> dependencies (as opposed to actions), especially when dealing with databases.
> Mainly, an interceptor is a singleton, so, if you are grabbing a resource via
> spring, and that resource depends on a database resource, could a pool or
> something be re-claiming it after excessive idle time?
Those are good suggestions--when I do get time to re-focus on this
problem I'll investigate that angle -- it may well be something like that.
Thanks,
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Dale Newfield <da...@newfield.org>.
Wes Wannemacher wrote:
> I jumped into the thread late and didn't see your original problems. I tend to
> peruse for things I can help on, so I'm not sure if I have an answer for your
> original problem :(
I wasn't the original poster. I don't think I ever saw the original
message, so let's hope that that person has resolved his or her issue.
:-) If not, please remind us of what it was! (I'm like you--I don't
have time to read the full list these days, so I look for messages with
subject lines on which I might be able to offer advice--in this case I
took an interest in a thread for selfish reasons rather than helpful ones.)
> Although, there are a few considerations for interceptors and their
> dependencies (as opposed to actions), especially when dealing with databases.
> Mainly, an interceptor is a singleton, so, if you are grabbing a resource via
> spring, and that resource depends on a database resource, could a pool or
> something be re-claiming it after excessive idle time?
Those are good suggestions--when I do get time to re-focus on this
problem I'll investigate that angle -- it may well be something like that.
Thanks,
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Wes Wannemacher <we...@wantii.com>.
On Tuesday 17 February 2009 19:19:08 Dale Newfield wrote:
>
> > The interceptor depends on the SpringObjectFactory, so it is necessary to
> > have the Spring plugin installed.
>
> Is it appropriate for struts to be distributed with an interceptor that
> doesn't work without the plugin? Doesn't that argue that the
> interceptor should be packaged *with* the plugin?
>
The nature of the interceptor is that it is not invoked unless it is
contextually relevant. Why it hasn't been moved into the Spring plugin? Most
likely this interceptor is older than the plugin itself. From a quick look at
the Spring plugin source, this interceptor is defined in its struts-plugin.xml
so even though it is a part of XWork2 rather than the plugin, it is likely to
stay there because it'll probably take some effort to move (moving and
refactoring unit tests, etc.).
I jumped into the thread late and didn't see your original problems. I tend to
peruse for things I can help on, so I'm not sure if I have an answer for your
original problem :(
Although, there are a few considerations for interceptors and their
dependencies (as opposed to actions), especially when dealing with databases.
Mainly, an interceptor is a singleton, so, if you are grabbing a resource via
spring, and that resource depends on a database resource, could a pool or
something be re-claiming it after excessive idle time?
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Dale Newfield <da...@newfield.org>.
Wes Wannemacher wrote:
> http://struts.apache.org/2.1.6/struts2-
> core/apidocs/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.html
>
> It's a bit confusing, but it really depends on how you want autowiring to
> happen.
I've been happily using the spring plugin which wires up my actions
(because they're defined as spring beans--I think I'd missed that
point--thanks for the clarification :-).
The bit that's been causing me grief lately isn't autowiring the
actions, though, but autowiring a custom interceptor based on
http://cwiki.apache.org/WW/hibernateandspringenabledexecuteandwaitinterceptor.html
That interceptor needs the hibernate SessionFactory so it can create a
long-lived session to go along with the long-running process.
I've not focused on debugging this, yet (bigger fish to fry at the
moment) but I believe in 2.1.6 I'm having difficulty because this
interceptor isn't always being wired up correctly.
I did recently add a definition for this interceptor to my
WEB-INF/action-servlet.xml -- maybe that was the source of my troubles?
I don't think that cleared up my issues, though. When I have time to
track this down I'll find out.
> The interceptor depends on the SpringObjectFactory, so it is necessary to have
> the Spring plugin installed.
Is it appropriate for struts to be distributed with an interceptor that
doesn't work without the plugin? Doesn't that argue that the
interceptor should be packaged *with* the plugin?
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Wes Wannemacher <we...@wantii.com>.
On Tuesday 17 February 2009 15:03:20 Dale Newfield wrote:
> Wes Wannemacher wrote:
> > There is a Spring autowiring interceptor that will autowire services into
> > your actions for you, even if you don't use Spring to instantiate the
> > actions.
>
> OK, now I'm confused. What's the interaction between the "autowiring"
> interceptor and the spring plugin? If we're using the spring plugin
> should we avoid that interceptor, or do we need it?
>
> -Dale
>
http://struts.apache.org/2.1.6/struts2-
core/apidocs/com/opensymphony/xwork2/spring/interceptor/ActionAutowiringInterceptor.html
It's a bit confusing, but it really depends on how you want autowiring to
happen. As you can see, the javadoc is littered with TODOs :)
This interceptor is not necessary if you are using Spring to instantiate your
actions... Meaning, if your actions are Spring beans configured in
applicationContext.xml (or whatever Spring configuration method you choose).
If Spring instantiates the action, then Spring will do the dependency wiring,
via whatever method is configured within Spring (and only Spring).
This interceptor comes into play when you are using Struts' non-Spring object
factories. For instance, in my case, I use convention which instantiates
actions by scanning my classpath and looking for classes marked with @Action
or that match the naming convention (PersonManagerAction). At first, I thought
by using convention, I would have to lookup dependencies in a Spring context,
but it turns out that this interceptor will autowire spring beans by
name/type/etc. depending on how it's configured.
The interceptor depends on the SpringObjectFactory, so it is necessary to have
the Spring plugin installed.
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Dale Newfield <da...@newfield.org>.
Wes Wannemacher wrote:
> There is a Spring autowiring interceptor that will autowire services into your
> actions for you, even if you don't use Spring to instantiate the actions.
OK, now I'm confused. What's the interaction between the "autowiring"
interceptor and the spring plugin? If we're using the spring plugin
should we avoid that interceptor, or do we need it?
-Dale
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Wes Wannemacher <we...@wantii.com>.
On Monday 16 February 2009 13:47:50 Sundararaman, Anand wrote:
> The validation is fine as it works when I scope my actions as singleton in
> the applicationContext.xml. Problem happens only when I scope them as
> prototype.
>
> When you say that Struts will try to use Spring to create all framework
> objects, is it possible to configure such a way that the action classes are
> instantiated by Struts but later they are autowired to Spring service
> beans. If possible can you direct me on how to configure that way?
>
There is a Spring autowiring interceptor that will autowire services into your
actions for you, even if you don't use Spring to instantiate the actions. It
is pretty slick. I use it with the convention plugin, I set the autowiring to
"by name" and then let convention configure the actions/dispatches and then
get magically wired with services. This cuts down the Spring XML quite a bit
since I only have the beans configured and Struts configuration is nearly nil.
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
The validation is fine as it works when I scope my actions as singleton in the applicationContext.xml. Problem happens only when I scope them as prototype.
When you say that Struts will try to use Spring to create all framework objects, is it possible to configure such a way that the action classes are instantiated by Struts but later they are autowired to Spring service beans. If possible can you direct me on how to configure that way?
Thanks,
Anand
-----Original Message-----
From: Lukasz Lenart [mailto:lukasz.lenart@googlemail.com]
Sent: Sunday, February 15, 2009 2:02 PM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
2009/2/15 Sundararaman, Anand <An...@ps.net>:
> No it did not work with that change as well.
>
> Initially I was getting a "NoSuchMethodException" on the method activateUser in the action class. Now after the change you suggested, it asked for an "input" result type in the action class. If I give the "input" result type it just does not go to that method nor the execute method and comes back to the original screen with action errors displayed.
"input" result is needed for validation purpose, if validation fail,
interceptor will return to "input" result, which means you have some
problem with validation and maybe that's the root of your problems.
Remember that if you enable integration with Spring, Strust will try
to use Spring to create all framework objects, from actions to
interceptors.
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/2/15 Sundararaman, Anand <An...@ps.net>:
> No it did not work with that change as well.
>
> Initially I was getting a "NoSuchMethodException" on the method activateUser in the action class. Now after the change you suggested, it asked for an "input" result type in the action class. If I give the "input" result type it just does not go to that method nor the execute method and comes back to the original screen with action errors displayed.
"input" result is needed for validation purpose, if validation fail,
interceptor will return to "input" result, which means you have some
problem with validation and maybe that's the root of your problems.
Remember that if you enable integration with Spring, Strust will try
to use Spring to create all framework objects, from actions to
interceptors.
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
No it did not work with that change as well.
Initially I was getting a "NoSuchMethodException" on the method activateUser in the action class. Now after the change you suggested, it asked for an "input" result type in the action class. If I give the "input" result type it just does not go to that method nor the execute method and comes back to the original screen with action errors displayed.
________________________________________
From: Lukasz Lenart [lukasz.lenart@googlemail.com]
Sent: Saturday, February 14, 2009 10:39 AM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
2009/2/14 Sundararaman, Anand <An...@ps.net>:
> <action name="activateUser" class="createUser" method="activateUser">
> <result name="success">/jsp/user/useractivated.jsp</result>
> <result name="error">/jsp/user/login.jsp</result>
> </action>
> </package>
That's really strange, did you try to use method="doActivateUser" ?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/2/14 Sundararaman, Anand <An...@ps.net>:
> <action name="activateUser" class="createUser" method="activateUser">
> <result name="success">/jsp/user/useractivated.jsp</result>
> <result name="error">/jsp/user/login.jsp</result>
> </action>
> </package>
That's really strange, did you try to use method="doActivateUser" ?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
Hi,
Here are the files. I have just pasted only the contents to highlight the problem. The CreateUserAction has two methods, execute() and doActivateUser(). The execute is called for "saveUser" action. The doActivateUser() is called for "activateUser" action. If I specify the scope=prototype, the doActivateUser() fails. If I remove the scope=prototype, the doActivateUser() works but I loose thread safety. I want thread safety as well as able to use the do*() methods called from actions.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
<constant name="struts.ui.theme" value="main" />
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory.spring.autoWire" value="name" />
<include file="struts-default.xml"/>
<package name="default" namespace = "/" extends="struts-default">
.........
.........
<action name="newUser">
<result>/jsp/user/userregistration.jsp</result>
</action>
<action name="saveUser" class="createUser">
<result name="success">/jsp/user/saveuser.jsp</result>
<result name="error">/jsp/user/userregistration.jsp</result>
</action>
<action name="activateUser" class="createUser" method="activateUser">
<result name="success">/jsp/user/useractivated.jsp</result>
<result name="error">/jsp/user/login.jsp</result>
</action>
</package>
</struts>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
.....
.......
......
<bean id="createUser" class="CreateUserAction" scope="prototype">
<property name="userService">
<ref bean="userServiceTarget"/>
</property>
</bean>
<bean id="userServiceTarget" class="UserService">
<property name="UserDAO">
<ref bean="UserDAOTarget"/>
</property>
</bean>
<bean id="UserDAOTarget"
class="UserDAO" >
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
.....
......
</beans>
________________________________________
From: Lukasz Lenart [lukasz.lenart@googlemail.com]
Sent: Saturday, February 14, 2009 10:01 AM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
Could you copy-paste your struts.xml and Spring config regarding actions?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Lukasz Lenart <lu...@googlemail.com>.
Could you copy-paste your struts.xml and Spring config regarding actions?
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Struts2-Spring Integration Issue
Posted by "Sundararaman, Anand" <An...@ps.net>.
Hi Lukasz,
I am not using AOP. Will it make any difference if I use the Spring-AOP?
Thanks,
Anand
________________________________________
From: Lukasz Lenart [lukasz.lenart@googlemail.com]
Sent: Saturday, February 14, 2009 9:51 AM
To: Struts Users Mailing List
Subject: Re: Struts2-Spring Integration Issue
2009/2/14 Sundararaman, Anand <An...@ps.net>:
> It seems to me that I will never be able to use the Struts non-execute (do*) methods, if I integrate with Spring. I need Spring Framework since it helps a lot with hibernate calls.
>
> Would anyone be able to guide me, if I am missing something.
Do you use AOP? If so, please try to make your methods final, or not
specify your action's methods in AOP config
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2-Spring Integration Issue
Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/2/14 Sundararaman, Anand <An...@ps.net>:
> It seems to me that I will never be able to use the Struts non-execute (do*) methods, if I integrate with Spring. I need Spring Framework since it helps a lot with hibernate calls.
>
> Would anyone be able to guide me, if I am missing something.
Do you use AOP? If so, please try to make your methods final, or not
specify your action's methods in AOP config
Regards
--
Lukasz
http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org