How do i get a custom ValueEncoder under control of IOC?
I have a ValueEncoder that translates a id to a Object from a db.
public class PropertyTypeEncoder implements ValueEncoder<LookupPropertyType> {
@Inject
private Session session;
public PropertyTypeEncoder(Session session) {
this.session = session;
}
public String toClient(LookupPropertyType value) {
return String.valueOf(value.getId());
}
public LookupPropertyType toValue(String id) {
Criteria criteria = session.createCriteria(LookupPropertyType.class);
criteria.add(Restrictions.eq("id", Long.parseLong(id)));
LookupPropertyType type = (LookupPropertyType)criteria.uniqueResult();
return type;
}
}
To get it created of the web form I have:
@Property
private final PropertyTypeEncoder propertyTypeEncoder = new
PropertyTypeEncoder(this.session);
Im passing the Hibernate session via the constructer since this would not be
under the IOC’s control.
Is there a way to create this using the IOC so the inject works?
Thanks,
Damon
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]