2008/7/29 [EMAIL PROTECTED] <[EMAIL PROTECTED]>

> [...] First, might I make the assumption that type
> converters and validators can be represented as beans. Reason being is
> because I need to be able to do dependency injection via spring.


Converters as beans:  that's not a problem.  I have a similar setup with a
RegionConverter, and I inject the RegionDao inside the converter.  If you
use Spring 2.5 or above, you can use the following annotation (which is
infinitely handy)

import javax.annotation.Resource;
public class RegionConverter extends StrutsTypeConverter {
    @Resource(name = "regionDao") private RegionDao regionDao;
...
}

No need even for a setRegionDao() method!  It works great!  And the
definition of the Spring bean becomes merely:

<bean name="regionConverter"
class="com.mysite.locale.converters.RegionConverter" />

There again, no need to inject the reference to the "regionDao" bean! The
@Resource annotation does the work!

Now, as to the rest of your issue, I've never used ,properties files for
setting converters.  What if you tried with annotations?  Find the class
containing the property that requires a converter (usually it's the action,
but it could be the model if your action is ModelDriven).  Annotate that
class with @Conversion.  Then annotate the getter of that property with
@TypeConverter(converter = "beanName").  In my case, I have an action that
implements ModelDrive<User>, and here's an excerpt of what my User class
looks like:

import com.opensymphony.xwork2.conversion.annotations.Conversion;
import com.opensymphony.xwork2.conversion.annotations.TypeConversion;

@Conversion
public class User extends AbstractPersistentObject {
...
    private Region birthplace;

    @TypeConversion(converter = "regionConverter")
    public Region getBirthplace() { return birthplace; }
    public void setBirthplace(Region region) { this.birthplace = region; }
...
}


I hope that may help!

Reply via email to