The reason the "Owner" drop-down appears blank (or more correctly, contains one blank item) is that org.springframework.core.convert.ConversionService .convert(Object, TypeDescriptor, TypeDescriptor) is returning an empty String when asked to convert an Owner to a String. This in turn is because Roo generates the following converter in ApplicationConversionServiceFactoryBean_Roo_Conver sionService.aj:
Code:
public Converter ApplicationConversionServiceFactoryBean.getOwnerToStringConverter() {
return new org.springframework.core.convert.converter.Converter() {
public String convert(Owner owner) {
return new StringBuilder().toString();
}
};
}
The above code is generated by these two classes in o.s.r.addon.web.mvc.controller.converter:
- ConversionServiceMetadataProviderImpl
- ConversionServiceMetadata
The converter they generate concatenates the results of all getter methods except those that return:
- the ID
- the version
- a collection or array
- a domain type (e.g. Owner or Thing)
- a boolean or Boolean
- a type annotated with javax.persistence.Embedded
So if your domain type contains only those types of fields, you end up with an empty String. The workaround is to push in the above method and customise it as required, for example:
Code:
@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {
@Override
protected void installFormatters(FormatterRegistry registry) {
super.installFormatters(registry);
// Register application converters and formatters
}
// This method has been pushed in from the ITD
public Converter<Owner, String> getOwnerToStringConverter() {
return new org.springframework.core.convert.converter.Converter<rootest.domain.model.Owner, java.lang.String>() {
public String convert(Owner owner) {
Person party = owner.getParty();
return party.getFirstName() + " " + party.getSurname();
}
};
}
}
This is preferable to editing your JSPX files, as you only have to do it once (not for every JSPX file).
We're looking at how we might fix Roo to handle this scenario better; clearly an empty String is not very useful.