Spring Roo中SELECT的自定义标签 [英] Custom label for a SELECT in Spring Roo

查看:271
本文介绍了Spring Roo中SELECT的自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Spring Roo开始.在我的项目中,我必须拥有一对多关系的实体.在我的控制器中,当我编辑一个实体时,我得到一个HTML SELECT来选择另一个实体.我想在此SELECT中添加一个自定义标签.

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.

我试图在ApplicationConversionServiceFactoryBean中注册一个Converter:

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();
      }
    };
  }
}

这似乎不起作用,SELECT仍然充满着类似于Application.toString()的结果.

This doesnt seem to work, the SELECT is still filled with what looks like the result of Application.toString().

我想念什么?

推荐答案

我确实找到了解决方案.我仍然不知道这是不是对的...

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());
  }
}

这似乎适用于SELECT中的标签.是推荐的方法吗?

This seems to work for the labels in a SELECT. Is it the recommended way ?

这篇关于Spring Roo中SELECT的自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆