Francisco Hernandez wrote:
so if you define your actions in spring how would you go about defining the results and interceptor stacks for those actions?

You still use an "xwork.xml" file to define the actions' validators and results, but rather than using a real class name in the action's "class" attribute, put a spring bean id or name. In your spring application context simply create a prototype bean with the expected id or name.


For example, a really simple "xwork.xml" might look like this (DTD elided):

<action name="getUserInfo" class="user-info-bean">
  <result name="success">
    <param name="location">userInfo.jsp</param>
  </result>
</action>

and in your "applicationContext.xml" file:

<beans>
  <bean id="user-manager" class="com.opensymphony.user.UserManager">
    <constructor-arg>
      <value>osuser-memory.xml</value>
    </constructor-arg>
  </bean>

  <bean id="user-info-bean" class="org.pubbitch.actions.UserInfo"
    singleton="false">
    <property name="userManager">
      <ref bean="user-manager" />
    </property>
  </bean>
</beans>

When XWork asks asks for the "getUserInfo" action, Spring will do it's normal magic of wiring up any listed properties, and then the SpringObjectFactory passes that to XWork to use as a normal action. All that's changing is how the bean is obtained.

Two points:

*) Notice that in the Spring context, the bean is configured as a prototype. This is a necessity because of the way that XWork expects a new Action for each request.

*) The SpringObjectFactory falls back to the normal XWork behaviour when it can't find the given bean name in the spring context. This means that it's possible to create some beans using Spring and others using XWork's current behaviour, giving you a bit of flexibility.

If there's interest, I'll put together the other methods in SpringObjectFactory and also add a little caching so that "Class.forName()" is not executed every time the default object factory is used.

Regards,

Simon


------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Opensymphony-webwork mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to