views:

18

answers:

1

is it possible to inject a service reference into custom type converter?

my situation is quite typical in fact, I have a combo, which binds to collection of entities. On submit I get only an ID of selected entity and have to refetch the real object in my action. I was thinking about more elegant way to do this, and it seems like making an ID-to-entity custom converter which would perform fetching - would be a good idea.

But I failed trying to map a converter to Spring bean in the same fashion like actions...

A: 

Interesting question. Are you using the spring plugin ?. It is supposed to take care of service-objects creation, (and wiring with other services) for Struts2, and this should be able to include Type Converters. From here:

By using the struts2-spring-plugin in conjunction with type conversion, developers easily can use dependency injection to provide a converter with services

But I have not used that feature.

leonbloy
yes, I'm using this plugin for configuring and autowiring Actions from Spring. I actually gave a try declaring a Converter in the same fashion as Actions - Spring bean name instead of class in xwork-conversion.properties. That didn't work, but now I think it worth exploring how struts' object factory works, maybe a Converter can be created by struts but autowired by spring...Thanks for that link, it doesn't says how, but at list claims that somebody managed to do that! :)
Pavlo