玩!框架ENUM和Groovy问题 [英] play! framework ENUM and Groovy problem

查看:159
本文介绍了玩!框架ENUM和Groovy问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西 -

I have something like the following-

Woman.java

...
@Entity
public class Woman extends Model {

    public static enum Outcome {
        ALIVE, DEAD, STILL_BIRTH, LIVE_BIRTH, REGISTER
    }
    ...
}

File.java

...
@Entity
public class Form extends Model {
    ...
    public Outcome autoCreateEvent;
    ...
}

Create.html

Create.html

#{select "autoCreateEvent", items:models.Woman.Outcome.values(), id:'autoCreateEvent' /}

它将数据库中的ENUM值保存为OK。但是,当我重新加载/编辑时,问题就会上升。因为它使用ALIVE,DEAD等作为选项的值,所以它无法正常显示列表。

It saves ENUM value in DB, which is OK. But, when I reload/edit then the problem rises. Because it uses ALIVE, DEAD, etc. as the value for options so it can't show the list properly.

任何Insight?

推荐答案

如果我正确理解你的问题,你想使用 valueProperty labelProperty 选项中设置适当的值。如下:

If I understand your question properly you want to use the valueProperty and labelProperty to set the proper values in the option. Something like:

#{select "autoCreateEvent", items:models.Woman.Outcome.values(), valueProperty:'ordinal', labelProperty: 'name', id:'autoCreateEvent' /}

编辑:

为了这个工作,你需要调整一下这个枚举:

For this to work you will need to tweak the enum a bit, like this:

public enum Outcome {
  A,B;

  public int getOrdinal() {
     return ordinal();
  }

}

原因是Play#{ select}期望在 valueProperty labelProperty params中的getter,如果没有找到默认的枚举 toString

The reason is that Play #{select} expects getters in the valueProperty and labelProperty params, and when not found defaults to the enum toString

这篇关于玩!框架ENUM和Groovy问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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