I am starting with Spring Roo. In my project, I have to entities with a one-to-many relation. In my controller, when I edit one entity, I get an HTML SELECT to choose one of the other entity. I'd like to have a custom label in this SELECT.
I tried to register a Converter in my ApplicationConversionServiceFactoryBean :
public class ApplicationConversionServiceFactoryBean extends
FormattingConversionServiceFactoryBean {
@Override
protected void installFormatters(FormatterRegistry registry) {
super.installFormatters(registry);
// Register application converters and formatters
registry.addConverter(getApplicationConverter());
}
public Converter<Application, String> getApplicationConverter() {
return new Converter<Application, String>() {
@Override
public String convert(Application source) {
return "toto" + source.getName();
}
};
}
}
This doesnt seem to work, the SELECT i开发者_如何学Gos still filled with what looks like the result of Application.toString().
What am I missing ?
I did find a solution. I still dont know if it is the right one ...
public class ApplicationConversionServiceFactoryBean extends
FormattingConversionServiceFactoryBean {
static class ApplicationConverter implements Converter<Application, String> {
@Override
public String convert(Application source) {
return "toto" + source.getName();
}
}
@Override
protected void installFormatters(FormatterRegistry registry) {
super.installFormatters(registry);
// Register application converters and formatters
registry.addConverter(new ApplicationConverter());
}
}
This seems to work for the labels in a SELECT. Is it the recommended way ?
精彩评论