struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alberto A. Flores" <aaflo...@gmail.com>
Subject Re: Constructor with arguments
Date Tue, 03 Jun 2008 18:09:13 GMT
Thanks Brian,

Yes, I'm using Spring already. The way I fixed it was by having Spring 
instantiate the class (I wasn't doing that before). Problem was that now 
I need to maintain an additional XML file (for each class) which is what 
I was trying to avoid.

Spring will do for me for now.

Relph,Brian wrote:
>  
> 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 [mailto:aaflores@gmail.com] 
> 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
it.
> 

-- 

Alberto A. Flores
http://www.linkedin.com/in/aflores



Mime
View raw message