Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用play framework 2上的ManyToOne字段绑定表单请求_Java_Scala_Playframework_Playframework 2.0 - Fatal编程技术网

Java 使用play framework 2上的ManyToOne字段绑定表单请求

Java 使用play framework 2上的ManyToOne字段绑定表单请求,java,scala,playframework,playframework-2.0,Java,Scala,Playframework,Playframework 2.0,当我在模型“Item”中添加一个manytone字段时,我遇到了这个错误&我试图绑定相应的表单 Execution exception [IllegalStateException: No value] at line 31 => Item item = itemForm.bindFromRequest().get(); “项目”模型: 包装模型 @Entity public class Item extends Model { @Id public Long id

当我在模型“Item”中添加一个manytone字段时,我遇到了这个错误&我试图绑定相应的表单

Execution exception
[IllegalStateException: No value] at line 31

=> Item item = itemForm.bindFromRequest().get();
“项目”模型: 包装模型

@Entity 
public class Item extends Model {

    @Id
    public Long id;

    @ManyToOne
    @Constraints.Required
    @Formats.NonEmpty
    public Category category;

    @Constraints.Required
    public String title;

    @Constraints.Required
    public String content;

    public String picture;

    (..)    
}
表单视图

    @helper.form(action = routes.Application.newItem(), 'id -> "item_form", 'method -> "POST", 'enctype -> "multipart/form-data"){
    <fieldset>
        @helper.inputText(
        itemForm("title"),
        '_label -> "Titre"  )

        @helper.select(
        itemForm("category"), 
        helper.options(Category.list),
        '_label -> "Categorie")

        @helper.textarea(
        itemForm("content"),
        '_label -> "Description")

         @helper.inputFile(
         field = itemForm("picture"), 
         '_display -> "Attachment", 
         '_label -> Messages("Image") )
         <input type="submit" value="Ajouter">

    </fieldset>
    }

考虑到类别模型具有id字段,类别字段的表单视图应为

@helper.select(
        itemForm("category.id"), 
        helper.options(Category.list),
        '_label -> "Categorie")
@helper.select(
        itemForm("category.id"), 
        helper.options(Category.list),
        '_label -> "Categorie")