开发者

Custom label for a SELECT in Spring Roo

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 ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜