玩!框架ENUM和Groovy问题
我有类似以下内容的内容 -
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
#{select "autoCreateEvent", items:models.Woman.Outcome.values(), id:'autoCreateEvent' /}
它将 ENUM 值保存在数据库中,这是可以的。但是,当我重新加载/编辑时,问题就会出现。因为它使用 ALIVE、DEAD 等作为选项的值,所以它无法正确显示列表。
有什么见解吗?
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
#{select "autoCreateEvent", items:models.Woman.Outcome.values(), id:'autoCreateEvent' /}
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.
Any Insight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解您的问题,您希望使用
valueProperty
和labelProperty
在option
中设置正确的值。像这样的东西:编辑:
为此,您需要稍微调整枚举,如下所示:
原因是 Play #{select} 需要
valueProperty
和labelProperty
中的 getters code> params,未找到时默认为枚举toString
If I understand your question properly you want to use the
valueProperty
andlabelProperty
to set the proper values in theoption
. Something like:EDIT:
For this to work you will need to tweak the enum a bit, like this:
The reason is that Play #{select} expects getters in the
valueProperty
andlabelProperty
params, and when not found defaults to the enumtoString
要添加到前面的答案,请将其添加到您的枚举声明中:
确保使用以下声明:
您还可以在枚举中添加它:
如果您想在视图文件中显示国际化值,这将很有用(因为 toString 是显示时自动调用),但函数 name() 使用 toString(),因此您必须将 valueProperty 绑定到另一个函数,如下所示:
#select 使用:
To add to previous answer, add this to your Enum declaration:
Make sure to use the following declaration:
You can also add this in the Enum:
Which will be useful if you want to display the internationalized value in your view file (since toString is being called automatically when displayed) but function name() uses toString() so you will have to bind valueProperty to another function, as follow:
And the #select use: