Play Framework - "无效的价值"使用helpers.select时

时间:2016-03-02 10:13:57

标签: java playframework playframework-2.0

当我尝试在Play 2.4中提交表单时,我收到错误"无效值"。这是我的代码: 形式:

@helper.select(
    field = form("category"),
    options = categories.map {c =>
        c.name.toString -> c.name
    },
    '_default -> "Choose One"
)

表单提交的模型(与类别一对一):

@OneToOne
@Constraints.Required
@Column
public Category category;

类别模型:

@Entity
public class Category extends Model {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(nullable = false)
    public Long id;

    @Constraints.Required
    @Formats.NonEmpty
    @Column(nullable = false)
    public String name;

    @Constraints.Required
    @Formats.NonEmpty
    @Column(nullable = false)
    public String description;

    public Category(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public static Finder<String, Category> find = new Finder<String,   Category>(Category.class);

    public static List<Category> getCategories() {
        return find.all();
    }
}

表单会加载类别的ID和名称,就在我提交时,会发生错误。我想这可能是因为Play在搜索OneToOne关系时没有获得带有id的类别?

0 个答案:

没有答案