You can definitely inject from any of the XWork files,
struts-default.properties, struts.properties, struts.xml,
struts-default.xml, struts-plugin.xml. These are all configured in the
Dispatcher when the Container is created (I think).
-bp
Musachy Barroso wrote:
I tried that, I think the problem is where to define the constant. I
used default.properties, where the others are defined, but the
container complains that it cannot satisfy the dependency. Of all
examples I found on xwork, only one references the bean to be injected
by name (which might not be working either).
musachy
On Mon, Apr 21, 2008 at 10:57 PM, Jeromy Evans
<[EMAIL PROTECTED]> wrote:
Musachy Barroso wrote:
If I want to add a constant that can be injected in one of xwork
classes (like "devMode" for example), what do I need to do? Just
adding @Inject and defining the constant in default.properties in core
doesn't work. I don't know much about this whole guice black magic
thing :)
musachy
Here's some simple examples:
Setup some beans and constants in the Container with unique names:
http://code.google.com/p/struts2urlplugin/source/browse/trunk/struts2-url-plugin/src/main/resources/struts-plugin.xml
eg. 1. Inject constant into a bean
http://code.google.com/p/struts2urlplugin/source/browse/trunk/struts2-url-plugin/src/main/java/com/blueskyminds/struts2/urlplugin/URLPatternActionMapper.java
Line 333
@Inject("struts.urlplugin.actionMapConfiguration")
public void setMappingConfigurationName(String mappingConfigurationName)
{
this.mappingConfigurationName = mappingConfigurationName;
}
eg. 2. Inject Container into a bean to enable run-time lookup by name and
class:
@Inject
public void setContainer(Container container) {
this.container = container;
}
Line 116
mappingConfiguration = container.getInstance(ActionMapConfiguration.class,
mappingConfigurationName);
eg. 3. Inject Bean into another bean directly: exactly as per the container
injection. If there's only one instance it will bind, otherwise specify the
name, otherwise it will fail.
@Inject("defaultActionMapper")
public void setActionMapper(ActionMapper actionMapper) {...
It only gets complicated when you need to mix injection with beans created
outside the container, as described by Wes.
cheers,
Jeromy Evans
PS. this is far inferior to the current functionality of Guice.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]