玩!框架ENUM和Groovy问题 [英] play! framework ENUM and Groovy problem
问题描述
我有这样的东西 -
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屋!