Here's the property editor:
Code:
public class DomainObjectEditor extends PropertyEditorSupport {
private BaseDaoSupport dao;
private SimpleTypeConverter typeConverter = new SimpleTypeConverter();
public DomainObjectEditor( BaseDaoSupport dao ) {
this.dao = dao;
}
@Override
public String getAsText() {
Object obj = getValue();
if( obj == null ) {
return null;
}
if( obj instanceof DomainObject ) {
DomainObject domainObject = ( DomainObject ) obj;
return typeConverter.convertIfNecessary(
domainObject.getId(), String.class );
}
throw new IllegalArgumentException( "Value must be a DomainObject" );
}
@Override
public void setAsText( String text ) {
if( text == null || 0 == text.length() ) {
setValue( null );
return;
}
setValue( dao.find(
typeConverter.convertIfNecessary( text, Long.class ) ) );
}
}
It works perfectly. In fact, even though the tag is not properly selecting the value, spring mvc is still binding the selected option. Spring mvc is also binding the correct value as well when it goes to freemarker.
Man, I hate bugs like this. this is totally a bug in spring. I wonder how long it's been here. It's so annoying.