|
From: <jue...@we...> - 2003-11-12 12:25:23
|
Cameron,
Wow, that was a quick reply! :-)
Your approach of using Spring as action factory for XWork, IoC-wiring =
XWork action objects, is similar to Don Brown's Struts-Spring project =
where Spring is used as action factory for Struts, IoC-wiring Struts =
action objects. I generally tend to view Spring as middle tier component =
provider rather than action factory when used with other web frameworks.
As you've noted, you typically need some kind of double configuration =
for action factory usage: Spring wires the actions and gives them a =
name, but the web framework still needs to define the actions and link =
to the Spring action factory. I totally agree that the separation is =
cleaner when just accessing Spring components from such actions. The =
latter would also seamlessly allow for a Spring root web application =
context (with middle tier components) being accessed by various =
dispatcher servlets (with web actions), even by multiple different web =
MVC frameworks within the same web application!
The <ref>/ReferenceResolver idea should be easy to add to XWork, after =
all. XWork already has reflection-based setting of <param> parameters; =
<ref> references could use the very same mechanism. A =
SpringServletContextReferenceResolver for WebWork2 could fetch the =
ServletContext from a ThreadLocal, grab the root WebApplicationContext =
from the ServletContext, and resolve the reference name as bean name. A =
non-web SpringClassPathReferenceResolver could access a pre-loaded =
ClassPathXmlApplicationContext from a ThreadLocal, and resolve the =
reference name as bean name there.
I would be delighted to see that approach being adopted in =
XWork/WebWork2, as it would allow for a really nice and straightforward =
combination. In terms of timing, it would be good to settle that before =
both Spring 1.0 final (end of December) and WebWork2 final (any =
timeframe there?). I'm happy to help on the Spring side of things, but I =
guess we won't need any changes in Spring to allow for that kind of =
reference support in XWork.
Juergen
-----Original Message-----
From: spr...@li... =
[mailto:spr...@li...]On Behalf =
Of Cameron Braid
Sent: Wednesday, November 12, 2003 12:36 PM
To: spr...@li...
Subject: [[W3-SPAM]] - Re: [Springframework-developer] Re: WebWork2 =
integration (was: About MVC) - Email found in subject
j=FCrgen h=F6ller [werk3AT] wrote:
Hi Lars,
Cameron Braid has been working on XWork/WebWork2 integration and =
obviously been pleased with it (you can search our mailing list archives =
for the whole thread).
<quote>
The bean/@id attribute relaxing is fantastic thanks!
I can now use the Spring Framework as an Action Factory for=20
Xwork/WebWork with no duplcation of configuration, using spring to=20
define business related interceptors : components, transactions,=20
security and webwork to provide web/view oriented interceptors :=20
request-params, validation
xwork.xml snippet :
<package name=3D"admin" namespace=3D"/admin" extends=3D"default">
<action name=3D"update" class=3D"com.project.AdminUpdateAction" =
method=3D"txUpdate">
<result name=3D"redirect">read.action?id=3D${id}</result>
</action>
</package>
applicationContext.xml snippet :
<bean name=3D"/admin/update" =
class=3D"com.datacodex.spring.webwork.WebworkActionFactoryBean">
<property name=3D"sessionFactory">
<ref local=3D"sessionFactory"/>
</property>
<property name=3D"transactionManager">
<ref local=3D"transactionManager"/>
</property>
<property name=3D"transactionAttributes">
<ref local=3D"defaultActionTransactionAttributes"/>
</property>
</bean>
very simple, neat and clean !
Thanks guys for your fantastic framework.
Cameron.
</quote>
I don't know how his integration approach works in detail but it looks =
promising. Cameron, can you give any in-depth insights? I assume the =
WebworkActionFactoryBean creates the action, being given the class name =
from the XWork definition? How does XWork know that it needs to delegate =
to the corresponding WebWorkActionFactoryBean - I guess via some custom =
XWork action factory? How does that action factory look up the Spring =
application context?
=20
I have made a few posts on the webwork mailing list.
See =
http://www.mail-archive.com/ope...@li.../ms=
g05919.html to start the thread - since then I have attempted to =
implement some of these ideas.
A basic summary :
I extended the WebWork ServletDispatcher, writing a new =
SpringServletDispatcher, it makes a call to the static =
ActionProxyFactory.setFactory(new=20
SpringActionProxyFactory()). =20
SpringActionProxyFactory extends the DefaultActionProxyFactory which =
overrides createActionInvocation to use=20
a SpringActionInvocation
SpringActionInvocation extends DefaultActionInvocation which overrides =
createAction to delegate to =
WebApplicationContextUtils.getWebApplicationContext(servletContext).getBe=
an(beanName)=20
to use the factory within spring to contruct this action.
The servletContext is obtained using a webwork static helper that =
retrieves it from the action context (threadlocal)
This level of integration is only required if you want to use spring as =
the action factory.
Most often you will only want to use spring to provide the components =
that the actions use, which I think is a better soloution.
As an alternative, I still see value in extending XWork's XML action =
definition format with a <ref> tag, in addition to the existing <param> =
tag. Those ref tags could then get resolved via a ReferenceResolver =
interface, possibly with a SpringReferenceResolver implementation that =
looks up the reference names in an application context. I've suggested =
that a while ago, but I don't think that anyone has adopted the idea =
yet, as it involves an extension of the XWork core.
=20
I really like your idea of supporting an external ref type tag as core =
in xwork/webwork since it offers the simplest, and most elegent =
soloution.
<action name=3D"listAccounts" class=3D"project.controller.ListAccounts">
...
<ref name=3D"accountsDao">accountsDao</ref>
...
</action>
Using one of these later ideas means that the action and refrences are =
totally defined in the webwork configuration, and components are defined =
in spring, which is a good separation in my mind.
When using spring as the action facory I was starting to find it =
difficult to see what was going on in regards to the actions since some =
configuration was done in xwork.xml and some in the spring context.
I can have a go at adding <ref> support to the xwork configuration code =
- in my snadbox. In the meantime we can discuss further and see what =
the other webwork developers think.
Before reading about this idea, I implemented a simple prototype (not =
production ready) system to get components from spring using a webwork =
interceptor. =20
What happens here is you configure the interceptor in the xwork.xml file =
just like any other webwork interceptor, using parameter to provide a =
mapping of action proeprty to spring bean name.
see =
http://www.mail-archive.com/ope...@li.../ms=
g05957.html
A basic summary :
<action name=3D"listAccounts" class=3D"project.controller.ListAccounts">
...
<interceptor-ref name=3D"springComponent">
<param name=3D"mapping">
accountsDao=3DaccountsDao
</param>
</interceptor-ref>
...
</action>
this example reflectively invokes =
action.setAccountsDao(WebApplicationContextUtils.getWebApplicationContext=
(servletContext).getBean(beanName))
obtaining the servlet context from the action context.
I would prefer to use the <ref> tag since it is a lot more meaningful, =
and allows for plugable RefrenceResolvers .
Thanks,
Cameron
Juergen
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...]On Behalf
Of Lars Fischer
Sent: Wednesday, November 12, 2003 11:32 AM
To: spr...@li...
Subject: [[W3-SPAM]] - RE: [Springframework-developer] About MVC - Email
found in subject
I think it would be a good idea to put a focus on WebWork 2 integration.
WebWork is a very popular framework and I think Spring would gain
further popularity when providing a way to integrate WebWork "out of the
box".
IMO the main advantage of WebWork is that it's very easy to understand =
even
with missing documentation. Spring MVC maybe technically superior
(I don't know) but it's too complicated to get started with.
The combination of Spring as Container and WebWork 2 as MVC framework
is very powerful.
What do you think about this ?
Regards,
Lars
|