How do you update ManyToOne field in a form?

女生的网名这么多〃 提交于 2019-12-23 04:57:24

问题


The questions is all in the title :)

Using Play! Framework 2.0, I have a Model with a ManyToOne field to an other Model.

In the form, I show it with a Select id -> toString, but when I hit submit, I've got "Invalid value", because it expect an instance of that Model (I guess).

How can I do this?

Thanks for your help!


回答1:


Name of this select must be set as property.id

ie. if your model looks like

@Entity
public class Entry extends Model {

    @Id
    public Long id;

    public String title;

    @ManyToOne
    public User user;
}    

Your select should be writen like this:

@select(
    yourForm("user.id"),
    options(User.options),
    'id -> "user",
    '_label -> "Select user"
)


来源:https://stackoverflow.com/questions/10294037/how-do-you-update-manytoone-field-in-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!