struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Relph,Brian" <>
Subject RE: Constructor with arguments
Date Tue, 03 Jun 2008 18:06:41 GMT
The struts2 object factory uses xwork's object factory to create the actions:

public Object buildAction(String actionName, String namespace, ActionConfig config, Map extraContext)
throws Exception {
        return buildBean(config.getClassName(), extraContext);

Which, as you can guess, can only build object with public,no-arg constructors.

    public Object buildBean(Class clazz, Map extraContext) throws Exception {
        return clazz.newInstance();

There is a SpringObjectFactory available in xwork, which was extended in the spring plugin
as the StrutsSpringObjectFactory.  These allow you to use spring to configure your actions,
which if you don't mind autowiring-by-name, does not require any special work on your part.

When you say you rely on spring to build your actions, are you already using the spring plugin?
 I find it works well, and since I use spring for so many other things, I have no need to
get rid of it as a dependency.  If you don't want to use spring, you can create your own object
factory, and override either the buildAction or buildBean methods to handle other constructors.
 It seems like you will still need to find your constructor argument objects from somewhere
though, so wouldn't you need some DI framework to handle that anyway?

I think there is work being done to adopt Guice as the default DI framework, you could look
into that.

Brian Relph

-----Original Message-----
From: Alberto A. Flores [] 
Sent: Tuesday, June 03, 2008 10:36 AM
To: Struts Users Mailing List
Subject: Constructor with arguments

Does anyone know how to make Struts2 ObjectFactory instantiate actions with constructor-arguments.

I currently have to rely on Spring to handle that case, but would be nice to do it without


Alberto A. Flores

CONFIDENTIALITY NOTICE This message and any included attachments are from Cerner Corporation
and are intended only for the addressee. The information contained in this message is confidential
and may constitute inside or non-public information under international, federal, or state
securities laws. Unauthorized forwarding, printing, copying, distribution, or use of such
information is strictly prohibited and may be unlawful. If you are not the addressee, please
promptly delete this message and notify the sender of the delivery error by e-mail or you
may call Cerner's corporate offices in Kansas City, Missouri, U.S.A at (+1) (816)221-1024.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message